objectmapper-jsonmapper: Jackson 2.23.0 vs 3.3.0 side by side (ObjectMapper/JsonMapper guide rewrite)
Seven runnable programs P01-P07 plus five compile-failure files, JDK 25, no docs/ folder. Output in objectmapper-jsonmapper/output/ is regenerated by scripts/run-all.sh. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b75Ao6imWN5bj7FHVw
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
# objectmapper-jsonmapper
|
||||
|
||||
Runnable companion for the ankurm.com guide
|
||||
[Jackson ObjectMapper and JsonMapper (Jackson 2 and 3)](https://ankurm.com/jackson-objectmapper-guide/).
|
||||
Jackson 2 and Jackson 3 sit side by side on one classpath (they live in different packages), so the
|
||||
same input goes through both mappers in the same JVM and the output can be compared line by line.
|
||||
There is deliberately no `docs/` folder: all explanation lives in the post, and every number in it
|
||||
comes from a file in [`output/`](output).
|
||||
|
||||
```
|
||||
Jackson 3 3.3.0 tools.jackson.core:jackson-databind
|
||||
Jackson 2 2.23.0 com.fasterxml.jackson.core:jackson-databind (+ jsr310 for the java.time demo)
|
||||
jackson-annotations 2.23 com.fasterxml.jackson.core (shared by both majors, pulled in by Jackson 3)
|
||||
JDK Temurin 25.0.5+8
|
||||
```
|
||||
|
||||
Both 3.3.0 and 2.23.0 appeared on Maven Central on 2026-11-08 (directory listing of repo1.maven.org).
|
||||
|
||||
## Run
|
||||
|
||||
```bash
|
||||
cd objectmapper-jsonmapper
|
||||
./scripts/run-all.sh # compiles, runs P01-P07, compiles the broken/ files, rewrites output/
|
||||
```
|
||||
|
||||
Single program: `mvn -q compile` then
|
||||
`java -cp "target/classes:$(cat target/cp.txt)" com.ankurm.objectmapper.P03ReadWriteCookbook`
|
||||
(run `run-all.sh` once first so `target/cp.txt` exists).
|
||||
|
||||
Timing lines in `P07` are indicative and move between runs; everything else reproduces exactly.
|
||||
|
||||
## Programs
|
||||
|
||||
| File | What it shows | Output |
|
||||
|---|---|---|
|
||||
| [`Article.java`](src/main/java/com/ankurm/objectmapper/Article.java) | the annotation-free POJO every example uses | - |
|
||||
| [`P01TwoMappersSideBySide`](src/main/java/com/ankurm/objectmapper/P01TwoMappersSideBySide.java) | same write/read in both majors, and which classes they really are | [output](output/P01TwoMappersSideBySide.txt) |
|
||||
| [`P02ImmutableMapper`](src/main/java/com/ankurm/objectmapper/P02ImmutableMapper.java) | why Jackson 3 has no setters; `rebuild()`; Jackson 2 ignoring a late setting | [output](output/P02ImmutableMapper.txt) |
|
||||
| [`P03ReadWriteCookbook`](src/main/java/com/ankurm/objectmapper/P03ReadWriteCookbook.java) | String/byte[]/File/Path/streams, `TypeReference`, tree, `convertValue`, readers | [output](output/P03ReadWriteCookbook.txt) |
|
||||
| [`P04ConfigRecipes`](src/main/java/com/ankurm/objectmapper/P04ConfigRecipes.java) | defaults of both majors read from the enums, property order, the config recipe | [output](output/P04ConfigRecipes.txt) |
|
||||
| [`P05JavaTime`](src/main/java/com/ankurm/objectmapper/P05JavaTime.java) | `java.time` with and without the module | [output](output/P05JavaTime.txt) |
|
||||
| [`P06Exceptions`](src/main/java/com/ankurm/objectmapper/P06Exceptions.java) | checked vs unchecked exceptions, same bad input | [output](output/P06Exceptions.txt) |
|
||||
| [`P07SharedMapperThreads`](src/main/java/com/ankurm/objectmapper/P07SharedMapperThreads.java) | one mapper across 8 threads; shared vs per-call cost | [output](output/P07SharedMapperThreads.txt) |
|
||||
| [`src/broken/`](src/broken) | five Jackson 2 habits that fail to compile on Jackson 3 | [compiler messages](output/Broken-compile-errors.txt) |
|
||||
|
||||
## Gradle
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'tools.jackson.core:jackson-databind:3.3.0'
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user