Skip to content

Commit 54a6785

Browse files
emerkle826adutra
authored andcommitted
JAVA-2480: Upgrade Jackson to 2.10.0 (apache#1349)
1 parent beaad5f commit 54a6785

4 files changed

Lines changed: 23 additions & 22 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.3.0 (in progress)
66

7+
- [improvement] JAVA-2480: Upgrade Jackson to 2.10.0
78
- [documentation] JAVA-2505: Annotate Node.getHostId() as nullable
89
- [improvement] JAVA-1708: Support DSE "everywhere" replication strategy
910
- [improvement] JAVA-2471: Consider DSE version when parsing the schema

examples/src/main/java/com/datastax/oss/driver/examples/json/codecs/JacksonJsonCodec.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.datastax.oss.protocol.internal.util.Bytes;
2525
import com.fasterxml.jackson.core.JsonProcessingException;
2626
import com.fasterxml.jackson.databind.JavaType;
27-
import com.fasterxml.jackson.databind.ObjectMapper;
27+
import com.fasterxml.jackson.databind.json.JsonMapper;
2828
import com.fasterxml.jackson.databind.type.TypeFactory;
2929
import edu.umd.cs.findbugs.annotations.NonNull;
3030
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -52,28 +52,28 @@
5252
*/
5353
public class JacksonJsonCodec<T> implements TypeCodec<T> {
5454

55-
private final ObjectMapper objectMapper;
55+
private final JsonMapper jsonMapper;
5656
private final GenericType<T> javaType;
5757

5858
/**
5959
* Creates a new instance for the provided {@code javaClass}, using a default, newly-allocated
60-
* {@link ObjectMapper}.
60+
* {@link JsonMapper}.
6161
*
6262
* @param javaClass the Java class this codec maps to.
6363
*/
6464
public JacksonJsonCodec(Class<T> javaClass) {
65-
this(javaClass, new ObjectMapper());
65+
this(javaClass, JsonMapper.builder().build());
6666
}
6767

6868
/**
6969
* Creates a new instance for the provided {@code javaClass}, and using the provided {@link
70-
* ObjectMapper}.
70+
* JsonMapper}.
7171
*
7272
* @param javaClass the Java class this codec maps to.
7373
*/
74-
public JacksonJsonCodec(Class<T> javaClass, ObjectMapper objectMapper) {
74+
public JacksonJsonCodec(Class<T> javaClass, JsonMapper jsonMapper) {
7575
this.javaType = GenericType.of(javaClass);
76-
this.objectMapper = objectMapper;
76+
this.jsonMapper = jsonMapper;
7777
}
7878

7979
@NonNull
@@ -95,7 +95,7 @@ public ByteBuffer encode(@Nullable T value, @NonNull ProtocolVersion protocolVer
9595
return null;
9696
}
9797
try {
98-
return ByteBuffer.wrap(objectMapper.writeValueAsBytes(value));
98+
return ByteBuffer.wrap(jsonMapper.writeValueAsBytes(value));
9999
} catch (JsonProcessingException e) {
100100
throw new IllegalArgumentException(e.getMessage(), e);
101101
}
@@ -108,7 +108,7 @@ public T decode(@Nullable ByteBuffer bytes, @NonNull ProtocolVersion protocolVer
108108
return null;
109109
}
110110
try {
111-
return objectMapper.readValue(Bytes.getArray(bytes), toJacksonJavaType());
111+
return jsonMapper.readValue(Bytes.getArray(bytes), toJacksonJavaType());
112112
} catch (IOException e) {
113113
throw new IllegalArgumentException(e.getMessage(), e);
114114
}
@@ -122,7 +122,7 @@ public String format(T value) {
122122
}
123123
String json;
124124
try {
125-
json = objectMapper.writeValueAsString(value);
125+
json = jsonMapper.writeValueAsString(value);
126126
} catch (IOException e) {
127127
throw new IllegalArgumentException(e.getMessage(), e);
128128
}
@@ -141,7 +141,7 @@ public T parse(String value) {
141141
}
142142
String json = Strings.unquote(value);
143143
try {
144-
return (T) objectMapper.readValue(json, toJacksonJavaType());
144+
return (T) jsonMapper.readValue(json, toJacksonJavaType());
145145
} catch (IOException e) {
146146
throw new IllegalArgumentException(e.getMessage(), e);
147147
}

integration-tests/src/test/java/com/datastax/oss/driver/querybuilder/JacksonJsonCodec.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.datastax.oss.protocol.internal.util.Bytes;
2525
import com.fasterxml.jackson.core.JsonProcessingException;
2626
import com.fasterxml.jackson.databind.JavaType;
27-
import com.fasterxml.jackson.databind.ObjectMapper;
27+
import com.fasterxml.jackson.databind.json.JsonMapper;
2828
import com.fasterxml.jackson.databind.type.TypeFactory;
2929
import edu.umd.cs.findbugs.annotations.NonNull;
3030
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -33,16 +33,16 @@
3333

3434
public class JacksonJsonCodec<T> implements TypeCodec<T> {
3535

36-
private final ObjectMapper objectMapper;
36+
private final JsonMapper jsonMapper;
3737
private final GenericType<T> javaType;
3838

3939
JacksonJsonCodec(Class<T> javaClass) {
40-
this(javaClass, new ObjectMapper());
40+
this(javaClass, JsonMapper.builder().build());
4141
}
4242

43-
private JacksonJsonCodec(Class<T> javaClass, ObjectMapper objectMapper) {
43+
private JacksonJsonCodec(Class<T> javaClass, JsonMapper objectMapper) {
4444
this.javaType = GenericType.of(javaClass);
45-
this.objectMapper = objectMapper;
45+
this.jsonMapper = objectMapper;
4646
}
4747

4848
@NonNull
@@ -64,7 +64,7 @@ public ByteBuffer encode(@Nullable T value, @NonNull ProtocolVersion protocolVer
6464
return null;
6565
}
6666
try {
67-
return ByteBuffer.wrap(objectMapper.writeValueAsBytes(value));
67+
return ByteBuffer.wrap(jsonMapper.writeValueAsBytes(value));
6868
} catch (JsonProcessingException e) {
6969
throw new IllegalArgumentException(e.getMessage(), e);
7070
}
@@ -77,7 +77,7 @@ public T decode(@Nullable ByteBuffer bytes, @NonNull ProtocolVersion protocolVer
7777
return null;
7878
}
7979
try {
80-
return objectMapper.readValue(Bytes.getArray(bytes), toJacksonJavaType());
80+
return jsonMapper.readValue(Bytes.getArray(bytes), toJacksonJavaType());
8181
} catch (IOException e) {
8282
throw new IllegalArgumentException(e.getMessage(), e);
8383
}
@@ -91,7 +91,7 @@ public String format(T value) {
9191
}
9292
String json;
9393
try {
94-
json = objectMapper.writeValueAsString(value);
94+
json = jsonMapper.writeValueAsString(value);
9595
} catch (IOException e) {
9696
throw new IllegalArgumentException(e.getMessage(), e);
9797
}
@@ -110,7 +110,7 @@ public T parse(String value) {
110110
}
111111
String json = Strings.unquote(value);
112112
try {
113-
return (T) objectMapper.readValue(json, toJacksonJavaType());
113+
return (T) jsonMapper.readValue(json, toJacksonJavaType());
114114
} catch (IOException e) {
115115
throw new IllegalArgumentException(e.getMessage(), e);
116116
}

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
<hk2.version>2.5.0</hk2.version>
7070
<jax-rs.version>2.0.1</jax-rs.version>
7171
<jsr353-ri.version>1.1.4</jsr353-ri.version>
72-
<jackson.version>2.9.9</jackson.version>
73-
<jackson-databind.version>2.9.9.3</jackson-databind.version>
72+
<jackson.version>2.10.0</jackson.version>
73+
<jackson-databind.version>2.10.0</jackson-databind.version>
7474
</properties>
7575

7676
<dependencyManagement>

0 commit comments

Comments
 (0)