77package com .sybit .airtable ;
88
99
10+ import com .mashape .unirest .http .ObjectMapper ;
1011import com .mashape .unirest .http .Unirest ;
1112import com .sybit .airtable .converter .ListConverter ;
1213import com .sybit .airtable .converter .MapConverter ;
@@ -54,11 +55,24 @@ public class Airtable {
5455 * Configure, <code>AIRTABLE_API_KEY</code> passed by Java property, enviroment variable
5556 * or within credentials.properties.
5657 *
57- * @return configured Airtable object.
58+ * @return An Airtable instance configured with GsonObjectMapper
5859 * @throws com.sybit.airtable.exception.AirtableException Missing API-Key
5960 */
6061 @ SuppressWarnings ("UnusedReturnValue" )
6162 public Airtable configure () throws AirtableException {
63+ return this .configure (new GsonObjectMapper ());
64+ }
65+
66+ /**
67+ * Configure, <code>AIRTABLE_API_KEY</code> passed by Java property, enviroment variable
68+ * or within credentials.properties.
69+ *
70+ * @param objectMapper A custom ObjectMapper implementation
71+ * @return An Airtable instance configured with supplied ObjectMapper
72+ * @throws com.sybit.airtable.exception.AirtableException Missing API-Key
73+ */
74+ @ SuppressWarnings ("UnusedReturnValue" )
75+ public Airtable configure (ObjectMapper objectMapper ) throws AirtableException {
6276
6377 LOG .info ( "System-Property: Using Java property '-D" + AIRTABLE_API_KEY + "' to get apikey." );
6478 String airtableApi = System .getProperty (AIRTABLE_API_KEY );
@@ -71,7 +85,7 @@ public Airtable configure() throws AirtableException {
7185 airtableApi = getCredentialProperty (AIRTABLE_API_KEY );
7286 }
7387
74- return this .configure (airtableApi );
88+ return this .configure (airtableApi , objectMapper );
7589 }
7690
7791
@@ -80,12 +94,25 @@ public Airtable configure() throws AirtableException {
8094 * Configure Airtable.
8195 *
8296 * @param apiKey API-Key of Airtable.
83- * @return
97+ * @return An Airtable instance configured with GsonObjectMapper
8498 * @throws com.sybit.airtable.exception.AirtableException Missing API-Key
8599 */
86100 @ SuppressWarnings ("WeakerAccess" )
87101 public Airtable configure (String apiKey ) throws AirtableException {
88- return configure (new Configuration (apiKey , Configuration .ENDPOINT_URL ));
102+ return configure (apiKey , new GsonObjectMapper ());
103+ }
104+
105+ /**
106+ * Configure Airtable.
107+ *
108+ * @param apiKey API-Key of Airtable.
109+ * @param objectMapper A custom ObjectMapper implementation
110+ * @return
111+ * @throws com.sybit.airtable.exception.AirtableException Missing API-Key
112+ */
113+ @ SuppressWarnings ("WeakerAccess" )
114+ public Airtable configure (String apiKey , ObjectMapper objectMapper ) throws AirtableException {
115+ return configure (new Configuration (apiKey , Configuration .ENDPOINT_URL ), objectMapper );
89116 }
90117
91118 /**
@@ -96,6 +123,19 @@ public Airtable configure(String apiKey) throws AirtableException {
96123 */
97124 @ SuppressWarnings ("WeakerAccess" )
98125 public Airtable configure (Configuration config ) throws AirtableException {
126+ return configure (config , new GsonObjectMapper ());
127+ }
128+
129+
130+ /**
131+ *
132+ * @param config
133+ * @param objectMapper A custom ObjectMapper implementation
134+ * @return
135+ * @throws com.sybit.airtable.exception.AirtableException Missing API-Key or Endpoint
136+ */
137+ @ SuppressWarnings ("WeakerAccess" )
138+ public Airtable configure (Configuration config , ObjectMapper objectMapper ) throws AirtableException {
99139 if (config .getApiKey () == null ) {
100140 throw new AirtableException ("Missing Airtable API-Key" );
101141 }
@@ -113,22 +153,21 @@ public Airtable configure(Configuration config) throws AirtableException {
113153 setProxy (config .getEndpointUrl ());
114154
115155 // Only one time
116- Unirest .setObjectMapper (new GsonObjectMapper () );
156+ Unirest .setObjectMapper (objectMapper );
117157
118-
119158 // Add specific Converter for Date
120159 DateTimeConverter dtConverter = new DateConverter ();
121160 ListConverter lConverter = new ListConverter ();
122161 MapConverter thConverter = new MapConverter ();
123-
162+
124163 lConverter .setListClass (Attachment .class );
125164 thConverter .setMapClass (Thumbnail .class );
126165 dtConverter .setPattern ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
127-
166+
128167 ConvertUtils .register (dtConverter , Date .class );
129168 ConvertUtils .register (lConverter , List .class );
130169 ConvertUtils .register (thConverter , Map .class );
131-
170+
132171
133172 return this ;
134173 }
@@ -142,8 +181,8 @@ public Airtable configure(Configuration config) throws AirtableException {
142181 private void setProxy (String endpointUrl ) {
143182 final String httpProxy = System .getenv ("http_proxy" );
144183 if (httpProxy != null
145- && (endpointUrl .contains ("127.0.0.1" )
146- || endpointUrl .contains ("localhost" ))) {
184+ && (endpointUrl .contains ("127.0.0.1" )
185+ || endpointUrl .contains ("localhost" ))) {
147186 LOG .info ("Use Proxy: ignored for 'localhost' ann '127.0.0.1'" );
148187 Unirest .setProxy (null );
149188 } else if (httpProxy != null ) {
0 commit comments