Migrates from Jackson 2.x to Jackson 3.x
Recipe ID
org.openrewrite.java.jackson.UpgradeJackson_2_3Artifact
org.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()).
Usage
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:1.28.0Definition
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 - Replace
@JsonIgnorewith@JsonSetteron empty collection fieldsorg.openrewrite.java.jackson.ReplaceJsonIgnoreWithJsonSetter - 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 - 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