Skip to content

Commit c841388

Browse files
committed
Eliminating dependency on google http-client.
1 parent 0aceed3 commit c841388

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+326
-537
lines changed

pom.xml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,14 @@
5656
<scope>test</scope>
5757
</dependency>
5858
<dependency>
59-
<groupId>com.google.http-client</groupId>
60-
<artifactId>google-http-client</artifactId>
61-
<version>1.21.0</version>
62-
</dependency>
63-
<dependency>
64-
<groupId>com.google.http-client</groupId>
65-
<artifactId>google-http-client-jackson2</artifactId>
66-
<version>1.21.0</version>
59+
<groupId>org.apache.commons</groupId>
60+
<artifactId>commons-lang3</artifactId>
61+
<version>3.5</version>
6762
</dependency>
6863
<dependency>
6964
<groupId>com.fasterxml.jackson.core</groupId>
70-
<artifactId>jackson-core</artifactId>
71-
<version>2.1.3</version>
65+
<artifactId>jackson-databind</artifactId>
66+
<version>2.13.0</version>
7267
</dependency>
7368
</dependencies>
7469

src/main/java/com/smartystreets/api/ClientBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ClientBuilder {
3232
private final String US_REVERSE_GEO_API_URL = "https://us-reverse-geo.api.smartystreets.com/lookup";
3333

3434
private ClientBuilder() {
35-
this.serializer = new GoogleSerializer();
35+
this.serializer = new SmartySerializer();
3636
this.maxRetries = 5;
3737
this.maxTimeout = 10000;
3838
}
@@ -75,7 +75,7 @@ public ClientBuilder withSender(Sender sender) {
7575
}
7676

7777
/**
78-
* Changes the <b>Serializer</b> from the default <b>GoogleSerializer</b>.
78+
* Changes the <b>Serializer</b> from the default <b>SmartySerializer</b>.
7979
* @param serializer An object that implements the <b>Serializer</b> interface.
8080
* @return Returns <b>this</b> to accommodate method chaining.
8181
*/
@@ -121,7 +121,7 @@ public ClientBuilder withProxy(Proxy.Type proxyType, String proxyHost, int proxy
121121
* @return Returns <b>this</b> to accommodate method chaining.
122122
*/
123123
public ClientBuilder withDebug() {
124-
GoogleSender.enableLogging();
124+
SmartySender.enableLogging();
125125
return this;
126126
}
127127

@@ -180,9 +180,9 @@ private Sender buildSender() {
180180

181181
Sender sender;
182182
if (this.proxy != null)
183-
sender = new GoogleSender(this.maxTimeout, this.proxy);
183+
sender = new SmartySender(this.maxTimeout, this.proxy);
184184
else
185-
sender = new GoogleSender(this.maxTimeout);
185+
sender = new SmartySender(this.maxTimeout);
186186

187187
sender = new StatusCodeSender(sender);
188188

src/main/java/com/smartystreets/api/GoogleSerializer.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/main/java/com/smartystreets/api/GoogleSender.java renamed to src/main/java/com/smartystreets/api/SmartySender.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@
1515
import java.util.logging.LogRecord;
1616
import java.util.logging.Logger;
1717

18-
public class GoogleSender implements Sender {
18+
public class SmartySender implements Sender {
1919
private int maxTimeOut;
2020
private HttpClient client;
2121

22-
public GoogleSender() {
22+
public SmartySender() {
2323
this.maxTimeOut = 10000;
2424
this.client = HttpClient.newHttpClient();
2525
}
2626

27-
public GoogleSender(int maxTimeout) {
27+
public SmartySender(int maxTimeout) {
2828
this();
2929
this.maxTimeOut = maxTimeout;
3030
}
3131

32-
GoogleSender(int maxTimeOut, ProxySelector proxy) {
32+
SmartySender(int maxTimeOut, ProxySelector proxy) {
3333
this.maxTimeOut = maxTimeOut;
3434
this.client = HttpClient.newBuilder().proxy(proxy).build();
3535
}
3636

37-
GoogleSender(HttpClient client) {
37+
SmartySender(HttpClient client) {
3838
this();
3939
this.client = client;
4040
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.smartystreets.api;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
6+
import java.io.*;
7+
8+
public class SmartySerializer implements Serializer {
9+
10+
public SmartySerializer() {}
11+
12+
public byte[] serialize(Object obj) throws IOException {
13+
ObjectMapper mapper = new ObjectMapper();
14+
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
15+
return mapper.writeValueAsBytes(obj);
16+
}
17+
18+
public <T> T deserialize(byte[] payload, Class<T> type) throws IOException {
19+
ObjectMapper mapper = new ObjectMapper();
20+
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
21+
return mapper.readValue(payload, type);
22+
}
23+
}

src/main/java/com/smartystreets/api/international_autocomplete/Candidate.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
package com.smartystreets.api.international_autocomplete;
22

3-
import com.google.api.client.util.Key;
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.io.Serializable;
46

57
/**
68
* @see "https://smartystreets.com/docs/cloud/international-address-autocomplete-api#http-response"
79
*/
8-
public class Candidate {
10+
public class Candidate implements Serializable {
911
//region [ Fields ]
1012

11-
@Key("street")
1213
private String street;
13-
14-
@Key("locality")
1514
private String locality;
16-
17-
@Key("administrative_area")
1815
private String administrativeArea;
19-
20-
@Key("postal_code")
2116
private String postalCode;
22-
23-
@Key("country_iso3")
2417
private String countryISO3;
2518

2619
//region [ Fields ]
@@ -31,10 +24,13 @@ public class Candidate {
3124

3225
public String getLocality() { return locality; }
3326

27+
@JsonProperty("administrative_area")
3428
public String getAdministrativeArea() { return administrativeArea; }
3529

30+
@JsonProperty("postal_code")
3631
public String getPostalCode() { return postalCode; }
3732

33+
@JsonProperty("country_iso3")
3834
public String getCountryISO3() { return countryISO3; }
3935

4036
//endregion

src/main/java/com/smartystreets/api/international_autocomplete/Result.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.smartystreets.api.international_autocomplete;
22

3-
import com.google.api.client.util.Key;
3+
import java.io.Serializable;
44

5-
public class Result {
6-
@Key("candidates")
5+
public class Result implements Serializable {
76
private Candidate[] candidates;
87

98
public Candidate[] getCandidates() {

src/main/java/com/smartystreets/api/international_street/Analysis.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
package com.smartystreets.api.international_street;
22

3-
import com.google.api.client.util.Key;
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.io.Serializable;
46

57
/**
68
* @see "https://smartystreets.com/docs/cloud/international-street-api#analysis"
79
*/
8-
public class Analysis {
9-
@Key("verification_status")
10+
public class Analysis implements Serializable {
1011
private String verificationStatus;
11-
12-
@Key("address_precision")
1312
private String addressPrecision;
14-
15-
@Key("max_address_precision")
1613
private String maxAddressPrecision;
17-
18-
@Key("changes")
1914
private Changes changes;
2015

2116

17+
@JsonProperty("verification_status")
2218
public String getVerificationStatus() {
2319
return verificationStatus;
2420
}
2521

22+
@JsonProperty("address_precision")
2623
public String getAddressPrecision() {
2724
return addressPrecision;
2825
}
2926

27+
@JsonProperty("max_address_precision")
3028
public String getMaxAddressPrecision() {
3129
return maxAddressPrecision;
3230
}

src/main/java/com/smartystreets/api/international_street/Candidate.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
package com.smartystreets.api.international_street;
22

3-
import com.google.api.client.util.Key;
3+
import java.io.Serializable;
44

55
/**
66
* A candidate is a possible match for an address that was submitted.<br>
77
* A lookup can have multiple candidates if the address was ambiguous.
88
*
99
* @see "https://smartystreets.com/docs/cloud/international-street-api#root"
1010
*/
11-
public class Candidate extends RootLevel {
11+
public class Candidate extends RootLevel implements Serializable {
1212
//region [ Fields ]
1313

14-
@Key("components")
1514
private Components components;
16-
17-
@Key("metadata")
1815
private Metadata metadata;
19-
20-
@Key("analysis")
2116
private Analysis analysis;
2217

2318
//endregion

src/main/java/com/smartystreets/api/international_street/Changes.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.smartystreets.api.international_street;
22

3-
import com.google.api.client.util.Key;
3+
import java.io.Serializable;
44

5-
public class Changes extends RootLevel {
5+
public class Changes extends RootLevel implements Serializable {
66

77
//region [ Fields ]
88

9-
@Key("components")
109
private Components components;
1110

1211
//endregion

0 commit comments

Comments
 (0)