Migrates from Jackson 2.x to Jackson 3.x
org.openrewrite.java.jackson.UpgradeJackson_2_3org.openrewrite.recipe:rewrite-jacksonDefinition
Recipes41
- Migrate from Jackson Codehaus (legacy) to Jackson FasterXML
- Replace
IOExceptionwithJacksonExceptionin catch clauses - Replace
throw new IOException(..)inside Jackson serializer / deserializer overrides - Replace
nulltype inStdDeserializerconstructor with actual type - Use
DeserializationContext.readTreeAsValue()instead ofObjectCodec.treeToValue() - Declare
ObjectCodecvariables asObjectReadContextorObjectWriteContext - Update
lombok.configfor Jackson 3 compatibility - Use format alignment
ObjectMappers - Modernize legacy
jackson-corefeature constants - Remove redundant Jackson 3 feature flag configurations
- Remove Spring beans for modules built-in to Jackson 3
- Remove registrations of modules built-in to Jackson 3
- Migrate mapper setter calls to builder pattern
- Migrate factory setter calls to builder pattern
- Update configuration of serialization inclusion in
ObjectMapperfor Jackson 3 - Replace
disable(MapperFeature.AUTO_DETECT_*)withchangeDefaultVisibility()for Jackson 3 - Reorder method arguments
- Reorder method arguments
- Reorder method arguments
- Add missing Jackson dataformat dependencies
- Upgrade Jackson 2.x dependencies to 3.x
- Use the Jackson 3 object mapper factory of REST Assured
- Rename Jackson 2.x methods to 3.x equivalents
- Migrate relocated feature constants to DateTimeFeature and EnumFeature
- Replace constant with another constant
- Replace
ObjectMapper.copy()withrebuild().build() - Use modern date/time serialization defaults
- Replace removed
JsonGeneratorcapability methods withStreamWriteCapability - Add
@JsonCreatorto non-public constructors - Add comment to method invocations
- Add comment to method invocations
- Add comment to SimpleModule method calls on modules that no longer extend SimpleModule
- Add comment to method invocations
- Add comment to method invocations
- Update Jackson 2.x types to 3.x
- Use
JsonFactory.builder()overnew JsonFactoryBuilder() - Migrate deprecated
@JsonSerialize(include = ...)to@JsonInclude - Migrate
ObjectMapper.readValue(URL, ...)to useopenStream() - Update Jackson package names from 2.x to 3.x
- Remove dead
throwsdeclarations for unchecked Jackson exceptions - Simplify catch clauses for Jackson exceptions
Examples
xml
- xml
- Diff
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.19.0</version>
</dependency>
</dependencies>
</project>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.22</version>
</dependency>
</dependencies>
</project>
--- pom.xml
+++ pom.xml
@@ -10,1 +10,1 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
- <version>2.19.0</version>
+ <version>2.22</version>
</dependency>
java
- java
- Diff
import com.fasterxml.jackson.core.JsonGenerator;
class Test {
void test(JsonGenerator gen, Object value) throws Exception {
gen.writeObject(value);
}
}
import tools.jackson.core.JsonGenerator;
class Test {
void test(JsonGenerator gen, Object value) throws Exception {
gen.writePOJO(value);
}
}
@@ -1,1 +1,1 @@
-import com.fasterxml.jackson.core.JsonGenerator;
+import tools.jackson.core.JsonGenerator;
@@ -5,1 +5,1 @@
class Test {
void test(JsonGenerator gen, Object value) throws Exception {
- gen.writeObject(value);
+ gen.writePOJO(value);
}
java
- java
- Diff
import com.fasterxml.jackson.core.JsonFactory;
class Test {
JsonFactory factory = new JsonFactory();
}
import tools.jackson.core.json.JsonFactory;
class Test {
JsonFactory factory = JsonFactory.builder()
.build();
}
@@ -1,1 +1,1 @@
-import com.fasterxml.jackson.core.JsonFactory;
+import tools.jackson.core.json.JsonFactory;
@@ -4,1 +4,2 @@
class Test {
- JsonFactory factory = new JsonFactory();
+ JsonFactory factory = JsonFactory.builder()
+ .build();
}
Example 4
import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
@Value
@Builder
@Jacksonized
class MyDto {
String name;
int age;
}
java
- java
- Diff
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
class MySerializer extends JsonSerializer<String> {
@Override
public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeString(value.toUpperCase());
}
}
import tools.jackson.core.JsonGenerator;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.ValueSerializer;
class MySerializer extends ValueSerializer<String> {
@Override
public void serialize(String value, JsonGenerator gen, SerializationContext provider) {
gen.writeString(value.toUpperCase());
}
}
@@ -1,4 +1,3 @@
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import java.io.IOException;
+import tools.jackson.core.JsonGenerator;
+import tools.jackson.databind.SerializationContext;
+import tools.jackson.databind.ValueSerializer;
@@ -6,1 +5,1 @@
import java.io.IOException;
-class MySerializer extends JsonSerializer<String> {
+class MySerializer extends ValueSerializer<String> {
@Override
@@ -8,1 +7,1 @@
class MySerializer extends JsonSerializer<String> {
@Override
- public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ public void serialize(String value, JsonGenerator gen, SerializationContext provider) {
gen.writeString(value.toUpperCase());
java
- java
- Diff
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
class Test {
void parse(JsonParser parser) {
if (parser.currentToken() == JsonToken.FIELD_NAME) {
System.out.println("It's a field");
}
}
}
import tools.jackson.core.JsonParser;
import tools.jackson.core.JsonToken;
class Test {
void parse(JsonParser parser) {
if (parser.currentToken() == JsonToken.PROPERTY_NAME) {
System.out.println("It's a field");
}
}
}
@@ -1,2 +1,2 @@
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
+import tools.jackson.core.JsonParser;
+import tools.jackson.core.JsonToken;
@@ -6,1 +6,1 @@
class Test {
void parse(JsonParser parser) {
- if (parser.currentToken() == JsonToken.FIELD_NAME) {
+ if (parser.currentToken() == JsonToken.PROPERTY_NAME) {
System.out.println("It's a field");
java
- java
- Diff
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
class Test {
void example(JsonGenerator gen) {
throw new JsonGenerationException("message", gen);
}
}
import tools.jackson.core.JsonGenerator;
import tools.jackson.core.exc.StreamWriteException;
class Test {
void example(JsonGenerator gen) {
throw new StreamWriteException(gen, "message");
}
}
@@ -1,2 +1,2 @@
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.core.JsonGenerator;
+import tools.jackson.core.JsonGenerator;
+import tools.jackson.core.exc.StreamWriteException;
@@ -6,1 +6,1 @@
class Test {
void example(JsonGenerator gen) {
- throw new JsonGenerationException("message", gen);
+ throw new StreamWriteException(gen, "message");
}
java
- java
- Diff
import com.fasterxml.jackson.databind.ObjectMapper;
import io.restassured.config.ObjectMapperConfig;
class PersonResourceTest {
ObjectMapperConfig config() {
return new ObjectMapperConfig().jackson2ObjectMapperFactory((type, s) -> new ObjectMapper());
}
}
import tools.jackson.databind.json.JsonMapper;
import io.restassured.config.ObjectMapperConfig;
class PersonResourceTest {
ObjectMapperConfig config() {
return new ObjectMapperConfig().jackson3ObjectMapperFactory((type, s) -> new JsonMapper());
}
}
@@ -1,1 +1,1 @@
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
import io.restassured.config.ObjectMapperConfig;
@@ -6,1 +6,1 @@
class PersonResourceTest {
ObjectMapperConfig config() {
- return new ObjectMapperConfig().jackson2ObjectMapperFactory((type, s) -> new ObjectMapper());
+ return new ObjectMapperConfig().jackson3ObjectMapperFactory((type, s) -> new JsonMapper());
}
java
- java
- Diff
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
class MyDeserializer extends StdDeserializer<String> {
public MyDeserializer() {
this(null);
}
public MyDeserializer(Class<?> vc) {
super(vc);
}
@Override
public String deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException {
return p.getValueAsString();
}
}
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.deser.std.StdDeserializer;
class MyDeserializer extends StdDeserializer<String> {
public MyDeserializer() {
this(String.class);
}
public MyDeserializer(Class<?> vc) {
super(vc);
}
@Override
public String deserialize(JsonParser p, DeserializationContext ctxt) {
return p.getValueAsString();
}
}
@@ -1,4 +1,3 @@
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-import java.io.IOException;
+import tools.jackson.core.JsonParser;
+import tools.jackson.databind.DeserializationContext;
+import tools.jackson.databind.deser.std.StdDeserializer;
@@ -8,1 +7,1 @@
class MyDeserializer extends StdDeserializer<String> {
public MyDeserializer() {
- this(null);
+ this(String.class);
}
@@ -16,2 +15,1 @@
@Override
- public String deserialize(JsonParser p, DeserializationContext ctxt)
- throws IOException {
+ public String deserialize(JsonParser p, DeserializationContext ctxt) {
return p.getValueAsString();
java
- java
- Diff
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
class Test {
JavaType getType() {
return TypeFactory.defaultInstance().constructType(String.class);
}
}
import tools.jackson.databind.JavaType;
import tools.jackson.databind.type.TypeFactory;
class Test {
JavaType getType() {
return TypeFactory.createDefaultInstance().constructType(String.class);
}
}
@@ -1,2 +1,2 @@
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.type.TypeFactory;
+import tools.jackson.databind.JavaType;
+import tools.jackson.databind.type.TypeFactory;
@@ -6,1 +6,1 @@
class Test {
JavaType getType() {
- return TypeFactory.defaultInstance().constructType(String.class);
+ return TypeFactory.createDefaultInstance().constructType(String.class);
}
java
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.19.0</version>
</dependency>
</dependencies>
</project>
- java
- Diff
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonFactoryBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;
class Test {
public String foo(@JsonProperty("foo") String foo) {
return foo;
}
static void helloJackson() {
Object[] input = new Object[] { "one", "two" };
JsonFactory factory = new JsonFactoryBuilder().build();
}
}
import com.fasterxml.jackson.annotation.JsonProperty;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.core.json.JsonFactory;
class Test {
public String foo(@JsonProperty("foo") String foo) {
return foo;
}
static void helloJackson() {
Object[] input = new Object[] { "one", "two" };
JsonFactory factory = JsonFactory.builder().build();
}
}
@@ -2,3 +2,2 @@
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonFactoryBuilder;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.core.json.JsonFactory;
@@ -13,1 +12,1 @@
static void helloJackson() {
Object[] input = new Object[] { "one", "two" };
- JsonFactory factory = new JsonFactoryBuilder().build();
+ JsonFactory factory = JsonFactory.builder().build();
}
xml
- xml
- Diff
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.19.0</version>
</dependency>
</dependencies>
</project>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.22</version>
</dependency>
</dependencies>
</project>
--- pom.xml
+++ pom.xml
@@ -10,1 +10,1 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
- <version>2.19.0</version>
+ <version>2.22</version>
</dependency>
java
- java
- Diff
import com.fasterxml.jackson.core.JsonGenerator;
class Test {
void test(JsonGenerator gen, Object value) throws Exception {
gen.writeObject(value);
}
}
import tools.jackson.core.JsonGenerator;
class Test {
void test(JsonGenerator gen, Object value) throws Exception {
gen.writePOJO(value);
}
}
@@ -1,1 +1,1 @@
-import com.fasterxml.jackson.core.JsonGenerator;
+import tools.jackson.core.JsonGenerator;
@@ -5,1 +5,1 @@
class Test {
void test(JsonGenerator gen, Object value) throws Exception {
- gen.writeObject(value);
+ gen.writePOJO(value);
}
java
- java
- Diff
import com.fasterxml.jackson.core.JsonFactory;
class Test {
JsonFactory factory = new JsonFactory();
}
import tools.jackson.core.json.JsonFactory;
class Test {
JsonFactory factory = JsonFactory.builder()
.build();
}
@@ -1,1 +1,1 @@
-import com.fasterxml.jackson.core.JsonFactory;
+import tools.jackson.core.json.JsonFactory;
@@ -4,1 +4,2 @@
class Test {
- JsonFactory factory = new JsonFactory();
+ JsonFactory factory = JsonFactory.builder()
+ .build();
}
Example 15
import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
@Value
@Builder
@Jacksonized
class MyDto {
String name;
int age;
}
java
- java
- Diff
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
class MySerializer extends JsonSerializer<String> {
@Override
public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeString(value.toUpperCase());
}
}
import tools.jackson.core.JsonGenerator;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.ValueSerializer;
class MySerializer extends ValueSerializer<String> {
@Override
public void serialize(String value, JsonGenerator gen, SerializationContext provider) {
gen.writeString(value.toUpperCase());
}
}
@@ -1,4 +1,3 @@
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import java.io.IOException;
+import tools.jackson.core.JsonGenerator;
+import tools.jackson.databind.SerializationContext;
+import tools.jackson.databind.ValueSerializer;
@@ -6,1 +5,1 @@
import java.io.IOException;
-class MySerializer extends JsonSerializer<String> {
+class MySerializer extends ValueSerializer<String> {
@Override
@@ -8,1 +7,1 @@
class MySerializer extends JsonSerializer<String> {
@Override
- public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ public void serialize(String value, JsonGenerator gen, SerializationContext provider) {
gen.writeString(value.toUpperCase());
java
- java
- Diff
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
class Test {
void parse(JsonParser parser) {
if (parser.currentToken() == JsonToken.FIELD_NAME) {
System.out.println("It's a field");
}
}
}
import tools.jackson.core.JsonParser;
import tools.jackson.core.JsonToken;
class Test {
void parse(JsonParser parser) {
if (parser.currentToken() == JsonToken.PROPERTY_NAME) {
System.out.println("It's a field");
}
}
}
@@ -1,2 +1,2 @@
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
+import tools.jackson.core.JsonParser;
+import tools.jackson.core.JsonToken;
@@ -6,1 +6,1 @@
class Test {
void parse(JsonParser parser) {
- if (parser.currentToken() == JsonToken.FIELD_NAME) {
+ if (parser.currentToken() == JsonToken.PROPERTY_NAME) {
System.out.println("It's a field");
java
- java
- Diff
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
class Test {
void example(JsonGenerator gen) {
throw new JsonGenerationException("message", gen);
}
}
import tools.jackson.core.JsonGenerator;
import tools.jackson.core.exc.StreamWriteException;
class Test {
void example(JsonGenerator gen) {
throw new StreamWriteException(gen, "message");
}
}
@@ -1,2 +1,2 @@
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.core.JsonGenerator;
+import tools.jackson.core.JsonGenerator;
+import tools.jackson.core.exc.StreamWriteException;
@@ -6,1 +6,1 @@
class Test {
void example(JsonGenerator gen) {
- throw new JsonGenerationException("message", gen);
+ throw new StreamWriteException(gen, "message");
}
java
- java
- Diff
import com.fasterxml.jackson.databind.ObjectMapper;
import io.restassured.config.ObjectMapperConfig;
class PersonResourceTest {
ObjectMapperConfig config() {
return new ObjectMapperConfig().jackson2ObjectMapperFactory((type, s) -> new ObjectMapper());
}
}
import tools.jackson.databind.json.JsonMapper;
import io.restassured.config.ObjectMapperConfig;
class PersonResourceTest {
ObjectMapperConfig config() {
return new ObjectMapperConfig().jackson3ObjectMapperFactory((type, s) -> new JsonMapper());
}
}
@@ -1,1 +1,1 @@
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
import io.restassured.config.ObjectMapperConfig;
@@ -6,1 +6,1 @@
class PersonResourceTest {
ObjectMapperConfig config() {
- return new ObjectMapperConfig().jackson2ObjectMapperFactory((type, s) -> new ObjectMapper());
+ return new ObjectMapperConfig().jackson3ObjectMapperFactory((type, s) -> new JsonMapper());
}
java
- java
- Diff
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
class MyDeserializer extends StdDeserializer<String> {
public MyDeserializer() {
this(null);
}
public MyDeserializer(Class<?> vc) {
super(vc);
}
@Override
public String deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException {
return p.getValueAsString();
}
}
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.deser.std.StdDeserializer;
class MyDeserializer extends StdDeserializer<String> {
public MyDeserializer() {
this(String.class);
}
public MyDeserializer(Class<?> vc) {
super(vc);
}
@Override
public String deserialize(JsonParser p, DeserializationContext ctxt) {
return p.getValueAsString();
}
}
@@ -1,4 +1,3 @@
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-import java.io.IOException;
+import tools.jackson.core.JsonParser;
+import tools.jackson.databind.DeserializationContext;
+import tools.jackson.databind.deser.std.StdDeserializer;
@@ -8,1 +7,1 @@
class MyDeserializer extends StdDeserializer<String> {
public MyDeserializer() {
- this(null);
+ this(String.class);
}
@@ -16,2 +15,1 @@
@Override
- public String deserialize(JsonParser p, DeserializationContext ctxt)
- throws IOException {
+ public String deserialize(JsonParser p, DeserializationContext ctxt) {
return p.getValueAsString();
java
- java
- Diff
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
class Test {
JavaType getType() {
return TypeFactory.defaultInstance().constructType(String.class);
}
}
import tools.jackson.databind.JavaType;
import tools.jackson.databind.type.TypeFactory;
class Test {
JavaType getType() {
return TypeFactory.createDefaultInstance().constructType(String.class);
}
}
@@ -1,2 +1,2 @@
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.type.TypeFactory;
+import tools.jackson.databind.JavaType;
+import tools.jackson.databind.type.TypeFactory;
@@ -6,1 +6,1 @@
class Test {
JavaType getType() {
- return TypeFactory.defaultInstance().constructType(String.class);
+ return TypeFactory.createDefaultInstance().constructType(String.class);
}
java
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.19.0</version>
</dependency>
</dependencies>
</project>
- java
- Diff
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonFactoryBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;
class Test {
public String foo(@JsonProperty("foo") String foo) {
return foo;
}
static void helloJackson() {
Object[] input = new Object[] { "one", "two" };
JsonFactory factory = new JsonFactoryBuilder().build();
}
}
import com.fasterxml.jackson.annotation.JsonProperty;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.core.json.JsonFactory;
class Test {
public String foo(@JsonProperty("foo") String foo) {
return foo;
}
static void helloJackson() {
Object[] input = new Object[] { "one", "two" };
JsonFactory factory = JsonFactory.builder().build();
}
}
@@ -2,3 +2,2 @@
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonFactoryBuilder;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.core.json.JsonFactory;
@@ -13,1 +12,1 @@
static void helloJackson() {
Object[] input = new Object[] { "one", "two" };
- JsonFactory factory = new JsonFactoryBuilder().build();
+ JsonFactory factory = JsonFactory.builder().build();
}
Usage
Run this recipe
This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe UpgradeJackson_2_3
If the recipe is not available locally, then you can install it using:
RELEASE resolves to the newest release and LATEST to the newest build of any kind, including snapshots. Either one lets mod config recipes upgrade pull in later versions without editing this command; a pinned version stays where you put it.
- RELEASE
- LATEST
- Pinned version
mod config recipes jar install org.openrewrite.recipe:rewrite-jackson:RELEASE
mod config recipes jar install org.openrewrite.recipe:rewrite-jackson:LATEST
mod config recipes jar install org.openrewrite.recipe:rewrite-jackson:1.32.0
Data tables
Maven metadata failures
org.openrewrite.maven.table.MavenMetadataFailuresAttempts to resolve maven metadata that failed.
mod study . --last-recipe-run \
--data-table org.openrewrite.maven.table.MavenMetadataFailures
| Column | Description |
|---|---|
| Group id | The groupId of the artifact for which the metadata download failed. |
| Artifact id | The artifactId of the artifact for which the metadata download failed. |
| Version | The version of the artifact for which the metadata download failed. |
| Maven repository | The URL of the Maven repository that the metadata download failed on. |
| Snapshots | Does the repository support snapshots. |
| Releases | Does the repository support releases. |
| Failure | The reason the metadata download failed. |
Source files that had results
org.openrewrite.table.SourcesFileResultsSource files that were modified by the recipe run.
mod study . --last-recipe-run \
--data-table org.openrewrite.table.SourcesFileResults
| Column | Description |
|---|---|
| Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
| Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
| Recipe that made changes | The specific recipe that made a change. |
| Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
| Cycle | The recipe cycle in which the change was made. |
Source files that had search results
org.openrewrite.table.SearchResultsSearch results that were found during the recipe run.
mod study . --last-recipe-run \
--data-table org.openrewrite.table.SearchResults
| Column | Description |
|---|---|
| Source path of search result before the run | The source path of the file with the search result markers present. |
| Source path of search result after run the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Result | The trimmed printed tree of the LST element that the marker is attached to. |
| Description | The content of the description of the marker. |
| Recipe that added the search marker | The specific recipe that added the Search marker. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrorsThe details of all errors produced by a recipe run.
mod study . --last-recipe-run \
--data-table org.openrewrite.table.SourcesFileErrors
| Column | Description |
|---|---|
| Source path | The file that failed to parse. |
| Recipe that made changes | The specific recipe that made a change. |
| Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStatsStatistics used in analyzing the performance of recipes.
mod study . --last-recipe-run \
--data-table org.openrewrite.table.RecipeRunStats
| Column | Description |
|---|---|
| The recipe | The recipe whose stats are being measured both individually and cumulatively. |
| Source file count | The number of source files the recipe ran over. |
| Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
| Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. |
| Max scanning time (ns) | The max time scanning any one source file. |
| Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
| Max edit time (ns) | The max time editing any one source file. |