37 runnable examples covering the eight feature posts on ankurm.com, verified against Jackson 3.2.1 on Temurin 21.0.5. Every output committed under docs/ was produced by run-all.sh. Also documents 11 places where the published snippets do not compile or do not behave as printed against a real Jackson 3 build - most notably that writeValueAsString(List<Base>) silently drops the polymorphic type discriminator, so the post's serialised output cannot be read back.
61 lines
2.6 KiB
Markdown
61 lines
2.6 KiB
Markdown
# Part 0 — Jackson 101: setup and the ObjectMapper lifecycle
|
|
|
|
Post: <https://ankurm.com/jackson-java-tutorial/>
|
|
|
|
## A01 — first round-trip
|
|
|
|
[`A01FirstRoundTrip.java`](../src/main/java/com/ankurm/jackson3/part0setup/A01FirstRoundTrip.java)
|
|
|
|
A plain POJO out to JSON and back, using `JsonMapper.builder().build()` in place of
|
|
`new ObjectMapper()`. Note there is no `throws` clause: Jackson 3 exceptions are unchecked.
|
|
|
|
```
|
|
{"listPrice":79.99,"productId":1,"productName":"Mechanical Keyboard"}
|
|
Mechanical Keyboard
|
|
```
|
|
|
|
The property order is **alphabetical**, not declaration order — the post shows
|
|
`productId` first. That is not a Jackson 3 change; it is how getter-based POJOs have
|
|
always been introspected. Records behave differently. See
|
|
[Part 1 / B04](part1-objectmapper.md#b04--property-ordering).
|
|
|
|
## A02 — the shared mapper
|
|
|
|
[`A02SharedMapperConfiguration.java`](../src/main/java/com/ankurm/jackson3/part0setup/A02SharedMapperConfiguration.java)
|
|
|
|
The post's central rule — build once, share everywhere — is enforced by the API in
|
|
Jackson 3 rather than left to discipline. Three of the four lines people copy from
|
|
Jackson 2 configuration are unnecessary or invalid here:
|
|
|
|
| Jackson 2 line | Status in Jackson 3 |
|
|
|---|---|
|
|
| `.registerModule(new JavaTimeModule())` | Delete. Built in; the class does not exist under `tools.jackson`. |
|
|
| `.registerModule(new Jdk8Module())` | Delete. Same. |
|
|
| `.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)` | **Does not compile.** Moved to `DateTimeFeature`, and already off. |
|
|
| `.configure(FAIL_ON_UNKNOWN_PROPERTIES, false)` | Redundant — already the default. |
|
|
| `.setSerializationInclusion(NON_NULL)` | Replaced by `.changeDefaultPropertyInclusion(...)`. |
|
|
|
|
```
|
|
configured : {"invoiceId":500,"customerName":"Alice","issuedOn":"2026-04-09"}
|
|
defaults : {"invoiceId":500,"customerName":"Alice","issuedOn":"2026-04-09","note":null}
|
|
ObjectMapper set*() methods in Jackson 3: 0
|
|
```
|
|
|
|
The last line is the point: `tools.jackson.databind.ObjectMapper` has **zero** `set*`
|
|
methods. Reconfiguring a shared mapper is not discouraged in Jackson 3, it is impossible.
|
|
|
|
## A03 — the three processing models
|
|
|
|
[`A03ThreeProcessingModels.java`](../src/main/java/com/ankurm/jackson3/part0setup/A03ThreeProcessingModels.java)
|
|
|
|
The same payload read by data binding, the tree model and the streaming parser.
|
|
|
|
```
|
|
1. data binding : Order[orderId=1001, status=SHIPPED]
|
|
2. tree model : orderId=1001 status=SHIPPED
|
|
3. streaming : orderId=1001 status=SHIPPED
|
|
```
|
|
|
|
For what each approach costs on a real file, see
|
|
[Part 6 / G04](part6-streaming.md#g04--the-decision-table-measured).
|