Three Maven modules - jackson2-before (2.22.1), jackson3-after (3.2.1) and a coexistence module with BOTH majors on one classpath - so every claim in the two migration guides is executed rather than asserted. Paired class names make the before/after outputs directly diffable via run-all.sh. Confirms the guides on wire-format equivalence (10-case suite, zero mismatches), classpath coexistence and the collapse of four artifacts into one. Corrects nine points, including that enableDefaultTyping() is still present in Jackson 2.22.1 rather than removed in 2.16, and that the published "after" mapper snippet does not compile.
1.8 KiB
1.8 KiB
S03 — Custom serialiser and deserialiser renames
Guide: https://ankurm.com/jackson-3-vs-jackson-2/ ("Custom Serializers and Deserializers: Class Renames")
before/S03CustomHandlers.java ·
after/S03CustomHandlers.java
If your project has custom handlers, this is where the upgrade time goes. Every item below is a compile error until fixed.
| Jackson 2 | Jackson 3 |
|---|---|
JsonSerializer<T> |
ValueSerializer<T> |
JsonDeserializer<T> |
ValueDeserializer<T> |
SerializerProvider |
SerializationContext |
throws IOException |
remove — unchecked now |
gen.writeNumberField(...) |
gen.writeNumberProperty(...) |
gen.writeStringField(...) |
gen.writeStringProperty(...) |
p.getCodec().readTree(p) |
ctxt.readTree(p) |
new SimpleModule(name, Version) |
new SimpleModule(name) |
mapper.registerModule(m) |
builder.addModule(m) |
Output
Jackson 2 — jackson2-before
serialised : {"amount":19.99,"currency":"USD"}
deserialised : Money[amount=20.0, currencyCode=USD]
base classes : com.fasterxml.jackson.databind.JsonSerializer / com.fasterxml.jackson.databind.JsonDeserializer
Jackson 3 — jackson3-after
serialised : {"amount":19.99,"currency":"USD"}
deserialised : Money[amount=20.0, currencyCode=USD]
base classes : tools.jackson.databind.ValueSerializer / tools.jackson.databind.ValueDeserializer
Identical JSON on both sides; only the base class names differ. That is the useful result — this is a mechanical rename, not a behavioural change, so it is safe to do in bulk with OpenRewrite and review as a diff.