Migrates from Jackson 2.x to Jackson 3.x
Recipe ID
org.openrewrite.java.jackson.UpgradeJackson_2_3Artifactorg.openrewrite.recipe:rewrite-jacksonMigrate applications to the latest Jackson 3.x release. This recipe handles package changes (com.fasterxml.jackson -> tools.jackson), dependency updates, core class renames, exception renames, and method renames (e.g., JsonGenerator.writeObject() -> writePOJO(), JsonParser.getCurrentValue() -> currentValue()).
Composite recipejackson-3Apache 2.0
Add to your build
Get a download tokenSign in with GitHub or Google, and your token replaces YOUR_DOWNLOAD_TOKEN below. Free for open source recipes like this one.
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.java.jackson.UpgradeJackson_2_3")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-jackson:1.30.1")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.java.jackson.UpgradeJackson_2_3If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-jackson:RELEASEDefinition
This recipe runs the following recipes in order.
- Migrate from Jackson Codehaus (legacy) to Jackson FasterXML
org.openrewrite.java.jackson.CodehausToFasterXML - Replace
IOExceptionwithJacksonExceptionin catch clausesorg.openrewrite.java.jackson.IOExceptionToJacksonException - Replace
throw new IOException(..)inside Jackson serializer / deserializer overridesorg.openrewrite.java.jackson.ReplaceIOExceptionThrowInJacksonOverrides - Replace
nulltype inStdDeserializerconstructor with actual typeorg.openrewrite.java.jackson.StdDeserializerNullConstructor - Use
DeserializationContext.readTreeAsValue()instead ofObjectCodec.treeToValue()org.openrewrite.java.jackson.UseReadTreeAsValueInDeserializer - Update
lombok.configfor Jackson 3 compatibilityorg.openrewrite.java.jackson.LombokJacksonizedConfig - Use format alignment
ObjectMappersorg.openrewrite.java.jackson.UseFormatAlignedObjectMappers - Modernize legacy
jackson-corefeature constantsorg.openrewrite.java.jackson.UpgradeJackson_2_3_ModernizeJacksonCoreFeatures - Remove redundant Jackson 3 feature flag configurations
org.openrewrite.java.jackson.UpgradeJackson_2_3_RemoveRedundantFeatureFlags - Remove registrations of modules built-in to Jackson 3
org.openrewrite.java.jackson.RemoveBuiltInModuleRegistrations - Migrate mapper setter calls to builder pattern
org.openrewrite.java.jackson.MigrateMapperSettersToBuilder - Migrate factory setter calls to builder pattern
org.openrewrite.java.jackson.MigrateFactorySettersToBuilder - Update configuration of serialization inclusion in
ObjectMapperfor Jackson 3org.openrewrite.java.jackson.UpdateSerializationInclusionConfiguration - Replace
disable(MapperFeature.AUTO_DETECT_*)withchangeDefaultVisibility()for Jackson 3org.openrewrite.java.jackson.UpdateAutoDetectVisibilityConfiguration - Reorder method arguments
org.openrewrite.java.ReorderMethodArguments - Reorder method arguments
org.openrewrite.java.ReorderMethodArguments - Reorder method arguments
org.openrewrite.java.ReorderMethodArguments - Add missing Jackson dataformat dependencies
org.openrewrite.java.jackson.AddMissingJacksonDependencies - Upgrade Jackson 2.x dependencies to 3.x
org.openrewrite.java.jackson.UpgradeJackson_2_3_Dependencies - Rename Jackson 2.x methods to 3.x equivalents
org.openrewrite.java.jackson.UpgradeJackson_2_3_MethodRenames - Migrate relocated feature constants to DateTimeFeature and EnumFeature
org.openrewrite.java.jackson.UpgradeJackson_2_3_RelocatedFeatureConstants - Replace constant with another constant
org.openrewrite.java.ReplaceConstantWithAnotherConstant - Replace
ObjectMapper.copy()withrebuild().build()org.openrewrite.java.jackson.ReplaceObjectMapperCopy - Use modern date/time serialization defaults
org.openrewrite.java.jackson.UseModernDateTimeSerialization - Replace removed
JsonGeneratorcapability methods withStreamWriteCapabilityorg.openrewrite.java.jackson.ReplaceStreamWriteCapability - Add
@JsonCreatorto non-public constructorsorg.openrewrite.java.jackson.AddJsonCreatorToPrivateConstructors - Add comment to method invocations
org.openrewrite.java.AddCommentToMethodInvocations - Add comment to method invocations
org.openrewrite.java.AddCommentToMethodInvocations - Add comment to SimpleModule method calls on modules that no longer extend SimpleModule
org.openrewrite.java.jackson.CommentOutSimpleModuleMethodCalls - Add comment to method invocations
org.openrewrite.java.AddCommentToMethodInvocations - Add comment to method invocations
org.openrewrite.java.AddCommentToMethodInvocations - Update Jackson 2.x types to 3.x
org.openrewrite.java.jackson.UpgradeJackson_2_3_TypeChanges - Use
JsonFactory.builder()overnew JsonFactoryBuilder()org.openrewrite.java.jackson.UseJsonFactoryStaticBuilder - Migrate deprecated
@JsonSerialize(include = ...)to@JsonIncludeorg.openrewrite.java.jackson.JsonSerializeIncludeToJsonInclude - Migrate
ObjectMapper.readValue(URL, ...)to useopenStream()org.openrewrite.java.jackson.ReadValueUrlToOpenStream - Update Jackson package names from 2.x to 3.x
org.openrewrite.java.jackson.UpgradeJackson_2_3_PackageChanges - Remove dead
throwsdeclarations for unchecked Jackson exceptionsorg.openrewrite.java.jackson.RemoveDeadJacksonThrows - Simplify catch clauses for Jackson exceptions
org.openrewrite.java.jackson.SimplifyJacksonExceptionCatch
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats