1
0
Files
jackson2-to-3-migration/docs/s07-defaults-that-flipped.md
Ankur f0a7053fc9 Jackson 2 to 3 migration companion code
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.
2026-08-04 23:29:27 +05:30

62 lines
2.5 KiB
Markdown

# S07 — Defaults that flipped silently
Guide: <https://ankurm.com/jackson-3-vs-jackson-2/> ("Removed and Changed Default Features")
[`before/S07DefaultsThatFlipped.java`](../jackson2-before/src/main/java/com/ankurm/migration/before/S07DefaultsThatFlipped.java) ·
[`after/S07DefaultsThatFlipped.java`](../jackson3-after/src/main/java/com/ankurm/migration/after/S07DefaultsThatFlipped.java)
These are the expensive ones. No compile error, no warning — behaviour just changes.
The two programs run identical probes so the diff is the migration surface:
```bash
diff docs/output/before-S07DefaultsThatFlipped.txt \
docs/output/after-S07DefaultsThatFlipped.txt
```
## Output
**Jackson 2 — `jackson2-before`**
```
FAIL_ON_TRAILING_TOKENS : false
FAIL_ON_UNKNOWN_PROPERTIES : true
ALLOW_FINAL_FIELDS_AS_MUTATORS: true
DEFAULT_VIEW_INCLUSION : true
AUTO_DETECT_CREATORS exists : true
concatenated JSON -> accepted: OrderDto[orderId=1]
trailing garbage -> accepted: OrderDto[orderId=1]
unknown property -> rejected: UnrecognizedPropertyException
```
**Jackson 3 — `jackson3-after`**
```
FAIL_ON_TRAILING_TOKENS : true
FAIL_ON_UNKNOWN_PROPERTIES : false
ALLOW_FINAL_FIELDS_AS_MUTATORS: false
DEFAULT_VIEW_INCLUSION : false
AUTO_DETECT_CREATORS exists : false
concatenated JSON -> rejected: MismatchedInputException
trailing garbage -> rejected: StreamReadException
unknown property -> accepted: OrderDto[orderId=1]
```
| Setting | Jackson 2 | Jackson 3 | Effect |
|---|---|---|---|
| `FAIL_ON_TRAILING_TOKENS` | off | **on** | Concatenated or double-encoded JSON that used to parse now throws |
| `FAIL_ON_UNKNOWN_PROPERTIES` | **on** | off | Unknown fields are tolerated by default; strictness must be opted into |
| `ALLOW_FINAL_FIELDS_AS_MUTATORS` | on | **off** | Jackson no longer overwrites `final` fields by reflection |
| `DEFAULT_VIEW_INCLUSION` | on | **off** | Review any `@JsonView` usage |
| `AUTO_DETECT_CREATORS` | present | **gone** | Constant removed — but see below |
The `FAIL_ON_UNKNOWN_PROPERTIES` flip is worth dwelling on because it moves in the
*lenient* direction. Code that relied on a strict mapper to reject malformed payloads
silently stops rejecting them after the upgrade. If you were using deserialisation
failure as input validation, re-enable it explicitly.
On `AUTO_DETECT_CREATORS`: the constant is gone, but the behaviour it governed is not.
Single-argument constructors are still detected as delegating creators — demonstrated in
the [features repo](https://ankurm.com/git.app/asmhatre/jackson3-by-example).