File tree Expand file tree Collapse file tree 4 files changed +23
-13
lines changed
main/java/com/maxmind/geoip2
test/java/com/maxmind/geoip2/model Expand file tree Collapse file tree 4 files changed +23
-13
lines changed Original file line number Diff line number Diff line change 55import com .fasterxml .jackson .databind .InjectableValues ;
66import com .fasterxml .jackson .databind .MapperFeature ;
77import com .fasterxml .jackson .databind .ObjectMapper ;
8+ import com .fasterxml .jackson .databind .json .JsonMapper ;
89import com .maxmind .geoip2 .exception .*;
910import com .maxmind .geoip2 .model .CityResponse ;
1011import com .maxmind .geoip2 .model .CountryResponse ;
@@ -119,9 +120,10 @@ private WebServiceClient(Builder builder) {
119120 this .licenseKey = builder .licenseKey ;
120121 this .accountId = builder .accountId ;
121122
122- mapper = new ObjectMapper ();
123- mapper .disable (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS );
124- mapper .disable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES );
123+ mapper = JsonMapper .builder ()
124+ .disable (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS )
125+ .disable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
126+ .build ();
125127
126128 RequestConfig .Builder configBuilder = RequestConfig .custom ()
127129 .setConnectTimeout (builder .connectTimeout )
Original file line number Diff line number Diff line change 33import com .fasterxml .jackson .annotation .JsonInclude .Include ;
44import com .fasterxml .jackson .databind .MapperFeature ;
55import com .fasterxml .jackson .databind .ObjectMapper ;
6+ import com .fasterxml .jackson .databind .json .JsonMapper ;
67
78import java .io .IOException ;
89
@@ -14,10 +15,12 @@ public abstract class AbstractResponse {
1415 * @throws IOException if there is an error serializing the object to JSON.
1516 */
1617 public String toJson () throws IOException {
17- ObjectMapper mapper = new ObjectMapper ();
18- mapper .setSerializationInclusion (Include .NON_NULL );
19- mapper .setSerializationInclusion (Include .NON_EMPTY );
20- mapper .configure (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS , false );
18+ JsonMapper mapper = JsonMapper .builder ()
19+ .disable (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS )
20+ .serializationInclusion (Include .NON_NULL )
21+ .serializationInclusion (Include .NON_EMPTY )
22+ .build ();
23+
2124 return mapper .writeValueAsString (this );
2225 }
2326
Original file line number Diff line number Diff line change 33import com .fasterxml .jackson .annotation .JsonInclude ;
44import com .fasterxml .jackson .databind .MapperFeature ;
55import com .fasterxml .jackson .databind .ObjectMapper ;
6+ import com .fasterxml .jackson .databind .json .JsonMapper ;
67
78import java .io .IOException ;
89
@@ -14,10 +15,12 @@ public abstract class AbstractRecord {
1415 * @throws IOException if there is an error serializing the object to JSON.
1516 */
1617 public String toJson () throws IOException {
17- ObjectMapper mapper = new ObjectMapper ();
18- mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
19- mapper .setSerializationInclusion (JsonInclude .Include .NON_EMPTY );
20- mapper .configure (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS , false );
18+ JsonMapper mapper = JsonMapper .builder ()
19+ .disable (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS )
20+ .serializationInclusion (JsonInclude .Include .NON_NULL )
21+ .serializationInclusion (JsonInclude .Include .NON_EMPTY )
22+ .build ();
23+
2124 return mapper .writeValueAsString (this );
2225 }
2326
Original file line number Diff line number Diff line change 44import com .fasterxml .jackson .databind .JsonNode ;
55import com .fasterxml .jackson .databind .MapperFeature ;
66import com .fasterxml .jackson .databind .ObjectMapper ;
7+ import com .fasterxml .jackson .databind .json .JsonMapper ;
78import com .fasterxml .jackson .jr .ob .JSON ;
89import org .junit .Test ;
910
@@ -338,8 +339,9 @@ public void testIspSerialization() throws Exception {
338339 protected <T extends AbstractResponse > void testRoundTrip
339340 (Class <T > cls , String json )
340341 throws IOException {
341- ObjectMapper mapper = new ObjectMapper ();
342- mapper .configure (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS , false );
342+ JsonMapper mapper = JsonMapper .builder ()
343+ .disable (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS )
344+ .build ();
343345 InjectableValues inject = new InjectableValues .Std ().addValue (
344346 "locales" , Collections .singletonList ("en" ));
345347 T response = mapper .readerFor (cls ).with (inject ).readValue (json );
You can’t perform that action at this time.
0 commit comments