Migrates from Jackson 2.x to Jackson 3.x

Apache 2.0

Migrate 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_3
mod run . --recipe=org.openrewrite.java.jackson.UpgradeJackson_2_3

Install 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.

  1. Migrate from Jackson Codehaus (legacy) to Jackson FasterXML
  2. Replace IOException with JacksonException in catch clauses
  3. Replace throw new IOException(..) inside Jackson serializer / deserializer overrides
  4. Replace null type in StdDeserializer constructor with actual type
  5. Use DeserializationContext.readTreeAsValue() instead of ObjectCodec.treeToValue()
  6. Declare ObjectCodec variables as ObjectReadContext or ObjectWriteContext
  7. Update lombok.config for Jackson 3 compatibility
  8. Use format alignment ObjectMappers
  9. Modernize legacy jackson-core feature constants
  10. Remove redundant Jackson 3 feature flag configurations
  11. Remove Spring beans for modules built-in to Jackson 3
  12. Remove registrations of modules built-in to Jackson 3
  13. Migrate mapper setter calls to builder pattern
  14. Migrate factory setter calls to builder pattern
  15. Update configuration of serialization inclusion in ObjectMapper for Jackson 3
  16. Replace disable(MapperFeature.AUTO_DETECT_*) and visibility(..) with changeDefaultVisibility() for Jackson 3
  17. Reorder method arguments
  18. Reorder method arguments
  19. Reorder method arguments
  20. Add missing Jackson dataformat dependencies
  21. Upgrade Jackson 2.x dependencies to 3.x
  22. Use the Jackson 3 object mapper factory of REST Assured
  23. Rename Jackson 2.x methods to 3.x equivalents
  24. Migrate relocated feature constants to DateTimeFeature and EnumFeature
  25. Replace constant with another constant
  26. Replace ObjectMapper.copy() with rebuild().build()
  27. Replace LaissezFaireSubTypeValidator with an equivalent BasicPolymorphicTypeValidator
  28. Use modern date/time serialization defaults
  29. Replace removed JsonGenerator capability methods with StreamWriteCapability
  30. Add @JsonCreator to non-public constructors
  31. Add comment to method invocations
  32. Add comment to method invocations
  33. Add comment to SimpleModule method calls on modules that no longer extend SimpleModule
  34. Add comment to method invocations
  35. Add comment to method invocations
  36. Update Jackson 2.x types to 3.x
  37. Use JsonFactory.builder() over new JsonFactoryBuilder()
  38. Migrate deprecated @JsonSerialize(include = ...) to @JsonInclude
  39. Migrate ObjectMapper.readValue(URL, ...) to use openStream()
  40. Migrate ObjectMapper.readValue(node.traverse(), ...) to treeToValue(node, ...)
  41. Update Jackson package names from 2.x to 3.x
  42. Remove dead throws declarations for unchecked Jackson exceptions
  43. Simplify catch clauses for Jackson exceptions