Skip to content

Commit 3ff57a2

Browse files
brharringtonclaude
andauthored
update to jackson 3 (#643)
Update Jackson from 2.21.0 to 3.0.3 which changes the Maven group IDs from com.fasterxml.jackson.core to tools.jackson.core and the Java package names from com.fasterxml.jackson to tools.jackson. In Jackson 3, ObjectMapper is abstract so usages are updated to use JsonMapper, JsonFactory construction uses the builder pattern, deprecated methods like getCurrentToken and getText are replaced with currentToken and getString, JsonToken.FIELD_NAME is renamed to PROPERTY_NAME, and JsonLocation is renamed to TokenStreamLocation. ErrorMessage is annotated with @JsonPropertyOrder to preserve serialization order. Unused dependencies are also cleaned up from Dependencies.scala. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 06bc401 commit 3ff57a2

7 files changed

Lines changed: 43 additions & 41 deletions

File tree

iep-admin/src/main/java/com/netflix/iep/admin/ErrorMessage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
*/
1616
package com.netflix.iep.admin;
1717

18+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
19+
1820
/**
1921
* Represents an error response that should be sent to the user.
2022
*/
23+
@JsonPropertyOrder({"status", "message"})
2124
public class ErrorMessage {
2225

2326
private final int status;

iep-admin/src/main/java/com/netflix/iep/admin/JsonEncoder.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package com.netflix.iep.admin;
1717

18-
import com.fasterxml.jackson.core.JsonFactory;
19-
import com.fasterxml.jackson.core.JsonGenerator;
20-
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import tools.jackson.core.JsonEncoding;
19+
import tools.jackson.core.JsonGenerator;
20+
import tools.jackson.core.ObjectWriteContext;
21+
import tools.jackson.core.json.JsonFactory;
22+
import tools.jackson.databind.json.JsonMapper;
2123

2224
import java.io.IOException;
2325
import java.io.OutputStream;
@@ -27,14 +29,14 @@
2729
*/
2830
class JsonEncoder {
2931

30-
private static final ObjectMapper MAPPER = new ObjectMapper();
31-
private static final JsonFactory FACTORY = new JsonFactory();
32+
private static final JsonMapper MAPPER = new JsonMapper();
33+
private static final JsonFactory FACTORY = JsonFactory.builder().build();
3234

3335
@SuppressWarnings("unchecked")
3436
static void encode(Object obj, OutputStream out) throws IOException {
3537
if (obj instanceof Iterable<?>) {
3638
Iterable<Object> values = (Iterable<Object>) obj;
37-
try (JsonGenerator gen = FACTORY.createGenerator(out)) {
39+
try (JsonGenerator gen = FACTORY.createGenerator(ObjectWriteContext.empty(), out, JsonEncoding.UTF8)) {
3840
gen.writeStartArray();
3941
for (Object value : values) {
4042
MAPPER.writeValue(gen, value);

iep-servergroups/src/main/java/com/netflix/iep/servergroups/EddaLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package com.netflix.iep.servergroups;
1717

18-
import com.fasterxml.jackson.core.JsonParser;
19-
import com.fasterxml.jackson.core.JsonToken;
18+
import tools.jackson.core.JsonParser;
19+
import tools.jackson.core.JsonToken;
2020
import com.netflix.spectator.ipc.http.HttpClient;
2121
import com.netflix.spectator.ipc.http.HttpResponse;
2222
import org.slf4j.Logger;
@@ -91,7 +91,7 @@ private Instance decodeInstance(JsonParser jp) throws IOException {
9191
}
9292

9393
private List<Instance> decodeInstances(JsonParser jp) throws IOException {
94-
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
94+
if (jp.currentToken() == JsonToken.VALUE_NULL) {
9595
return Collections.emptyList();
9696
}
9797
List<Instance> vs = new ArrayList<>();

iep-servergroups/src/main/java/com/netflix/iep/servergroups/EurekaLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.netflix.iep.servergroups;
1717

18-
import com.fasterxml.jackson.core.JsonParser;
18+
import tools.jackson.core.JsonParser;
1919
import com.netflix.spectator.ipc.http.HttpClient;
2020
import com.netflix.spectator.ipc.http.HttpResponse;
2121

iep-servergroups/src/main/java/com/netflix/iep/servergroups/JsonUtils.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
*/
1616
package com.netflix.iep.servergroups;
1717

18-
import com.fasterxml.jackson.core.JsonFactory;
19-
import com.fasterxml.jackson.core.JsonLocation;
20-
import com.fasterxml.jackson.core.JsonParser;
21-
import com.fasterxml.jackson.core.JsonProcessingException;
22-
import com.fasterxml.jackson.core.JsonToken;
18+
import tools.jackson.core.JacksonException;
19+
import tools.jackson.core.JsonParser;
20+
import tools.jackson.core.JsonToken;
21+
import tools.jackson.core.ObjectReadContext;
22+
import tools.jackson.core.TokenStreamLocation;
23+
import tools.jackson.core.json.JsonFactory;
2324
import com.netflix.spectator.ipc.http.HttpResponse;
2425
import org.slf4j.Logger;
2526
import org.slf4j.LoggerFactory;
@@ -38,23 +39,23 @@ final class JsonUtils {
3839

3940
private static final Logger LOGGER = LoggerFactory.getLogger(JsonUtils.class);
4041

41-
private static final JsonFactory FACTORY = new JsonFactory();
42+
private static final JsonFactory FACTORY = JsonFactory.builder().build();
4243

4344
private static boolean isEndOfArrayOrInput(JsonParser jp) {
44-
JsonToken t = jp.getCurrentToken();
45+
JsonToken t = jp.currentToken();
4546
return t == null || t == JsonToken.END_ARRAY;
4647
}
4748

4849
private static boolean isEndOfObjectOrInput(JsonParser jp) {
49-
JsonToken t = jp.getCurrentToken();
50+
JsonToken t = jp.currentToken();
5051
return t == null || t == JsonToken.END_OBJECT;
5152
}
5253

5354
/** Check that the current token for the parser is of the expected type. */
5455
private static void expect(JsonParser jp, JsonToken expected) throws IOException {
55-
JsonToken actual = jp.getCurrentToken();
56+
JsonToken actual = jp.currentToken();
5657
if (actual != expected) {
57-
JsonLocation loc = jp.currentLocation();
58+
TokenStreamLocation loc = jp.currentLocation();
5859
throw new IllegalArgumentException(
5960
"invalid input: expected " + expected + ", received " + actual
6061
+ " (line " + loc.getLineNr() + ", column " + loc.getColumnNr() + ")");
@@ -63,7 +64,7 @@ private static void expect(JsonParser jp, JsonToken expected) throws IOException
6364

6465
/** Create a list from the current array value. */
6566
static <T> List<T> toList(JsonParser jp, IOFunction<T> f) throws IOException {
66-
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
67+
if (jp.currentToken() == JsonToken.VALUE_NULL) {
6768
return Collections.emptyList();
6869
}
6970
List<T> vs = new ArrayList<>();
@@ -78,7 +79,7 @@ static <T> void forEach(JsonParser jp, IOConsumer f) throws IOException {
7879
while (!isEndOfArrayOrInput(jp)) {
7980
f.apply(jp);
8081
}
81-
if (jp.getCurrentToken() == JsonToken.END_ARRAY) {
82+
if (jp.currentToken() == JsonToken.END_ARRAY) {
8283
jp.nextToken();
8384
}
8485
}
@@ -88,22 +89,22 @@ static <T> void forEachField(JsonParser jp, IOBiConsumer f) throws IOException {
8889
expect(jp, JsonToken.START_OBJECT);
8990
jp.nextToken();
9091
while (!isEndOfObjectOrInput(jp)) {
91-
expect(jp, JsonToken.FIELD_NAME);
92+
expect(jp, JsonToken.PROPERTY_NAME);
9293
jp.nextToken();
9394
f.apply(jp.currentName(), jp);
9495
}
95-
if (jp.getCurrentToken() == JsonToken.END_OBJECT) {
96+
if (jp.currentToken() == JsonToken.END_OBJECT) {
9697
jp.nextToken();
9798
}
9899
}
99100

100101
/** Extract a string value. */
101102
static String stringValue(JsonParser jp) throws IOException {
102-
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
103+
if (jp.currentToken() == JsonToken.VALUE_NULL) {
103104
return null;
104105
}
105106
expect(jp, JsonToken.VALUE_STRING);
106-
String v = jp.getText();
107+
String v = jp.getString();
107108
jp.nextToken();
108109
return v;
109110
}
@@ -114,7 +115,7 @@ static int intValue(JsonParser jp) throws IOException {
114115
int v = -1;
115116
try {
116117
v = jp.getIntValue();
117-
} catch (JsonProcessingException e) {
118+
} catch (JacksonException e) {
118119
LOGGER.warn("failed to parse value as integer", e);
119120
}
120121
jp.nextToken();
@@ -126,10 +127,10 @@ static int intValue(JsonParser jp) throws IOException {
126127
* tokens and set the position to the token after the end of the array or object.
127128
*/
128129
static void skipValue(JsonParser jp) throws IOException {
129-
if (jp.getCurrentToken() == null) {
130+
if (jp.currentToken() == null) {
130131
return;
131132
}
132-
switch (jp.getCurrentToken()) {
133+
switch (jp.currentToken()) {
133134
case START_ARRAY:
134135
case START_OBJECT:
135136
jp.skipChildren();
@@ -169,12 +170,12 @@ static List<ServerGroup> parseResponse(
169170
// full decompressed payload.
170171
try (
171172
GZIPInputStream gzin = new GZIPInputStream(new ByteArrayInputStream(response.entity()));
172-
JsonParser jp = FACTORY.createParser(gzin)
173+
JsonParser jp = FACTORY.createParser(ObjectReadContext.empty(), gzin)
173174
) {
174175
return function.apply(jp);
175176
}
176177
} else {
177-
try (JsonParser jp = FACTORY.createParser(response.entity())) {
178+
try (JsonParser jp = FACTORY.createParser(ObjectReadContext.empty(), response.entity())) {
178179
return function.apply(jp);
179180
}
180181
}

iep-spring-userservice/src/main/java/com/netflix/iep/userservice/Context.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.netflix.iep.userservice;
1717

18-
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import tools.jackson.databind.json.JsonMapper;
1919
import com.netflix.spectator.api.Registry;
2020
import com.netflix.spectator.ipc.http.HttpClient;
2121
import com.netflix.spectator.ipc.http.HttpRequestBuilder;
@@ -32,7 +32,7 @@
3232
/** Common settings used across all services. */
3333
public final class Context implements AutoCloseable {
3434

35-
private final ObjectMapper mapper = new ObjectMapper();
35+
private final JsonMapper mapper = new JsonMapper();
3636

3737
private final Registry registry;
3838

@@ -82,7 +82,7 @@ public void stop() {
8282
executor.shutdown();
8383
}
8484

85-
ObjectMapper objectMapper() {
85+
JsonMapper objectMapper() {
8686
return mapper;
8787
}
8888

project/Dependencies.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Dependencies {
44
object Versions {
55
val assertj = "3.27.7"
66
val aws2 = "2.41.22"
7-
val jackson = "2.21.0"
7+
val jackson = "3.0.3"
88
val scala = "2.12.20"
99
val slf4j = "2.0.17"
1010
val spectator = "1.9.4"
@@ -23,20 +23,16 @@ object Dependencies {
2323
val aws2UrlClient = "software.amazon.awssdk" % "url-connection-client" % aws2
2424
val caffeine = "com.github.ben-manes.caffeine" % "caffeine" % "3.2.3"
2525
val equalsVerifier = "nl.jqno.equalsverifier" % "equalsverifier" % "4.3.1"
26-
val jacksonCore = "com.fasterxml.jackson.core" % "jackson-core" % jackson
27-
val jacksonMapper = "com.fasterxml.jackson.core" % "jackson-databind" % jackson
26+
val jacksonCore = "tools.jackson.core" % "jackson-core" % jackson
27+
val jacksonMapper = "tools.jackson.core" % "jackson-databind" % jackson
2828
val jakartaAnno = "jakarta.annotation" % "jakarta.annotation-api" % "3.0.0"
2929
val jakartaInject = "jakarta.inject" % "jakarta.inject-api" % "2.0.1"
30-
val jodaTime = "joda-time" % "joda-time" % "2.10.10"
3130
val jedis = "redis.clients" % "jedis" % "7.2.1"
32-
val junit = "junit" % "junit" % "4.12"
3331
val junitInterface = "com.novocode" % "junit-interface" % "0.11"
34-
val jzlib = "com.jcraft" % "jzlib" % "1.1.3"
3532
val mockitoCore = "org.mockito" % "mockito-core" % "5.21.0"
3633
val slf4jApi = "org.slf4j" % "slf4j-api" % slf4j
3734
val spectatorApi = "com.netflix.spectator" % "spectator-api" % spectator
3835
val spectatorAtlas = "com.netflix.spectator" % "spectator-reg-atlas" % spectator
39-
val spectatorAws = "com.netflix.spectator" % "spectator-ext-aws" % spectator
4036
val spectatorGc = "com.netflix.spectator" % "spectator-ext-gc" % spectator
4137
val spectatorIpc = "com.netflix.spectator" % "spectator-ext-ipc" % spectator
4238
val spectatorJvm = "com.netflix.spectator" % "spectator-ext-jvm" % spectator

0 commit comments

Comments
 (0)