Migrates from Jackson 2.x to Jackson 3.x
Apache 2.0Migrate 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()).
org. openrewrite. java. jackson. UpgradeJackson_2_3mod run . --recipe= org. openrewrite. java. jackson. UpgradeJackson_2_3Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- 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_*)andvisibility(..)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() - Replace
LaissezFaireSubTypeValidatorwith an equivalentBasicPolymorphicTypeValidator - 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() - Migrate
ObjectMapper.readValue(node.traverse(), ...)totreeToValue(node, ...) - Update Jackson package names from 2.x to 3.x
- Remove dead
throwsdeclarations for unchecked Jackson exceptions - Simplify catch clauses for Jackson exceptions