1
0

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.
This commit is contained in:
2026-08-04 23:12:25 +05:30
commit f0a7053fc9
43 changed files with 1665 additions and 0 deletions

53
run-all.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# Builds all three modules and runs every example, writing real output to
# docs/output/<module>-<Class>.txt. The before/after pairs share a class name so
# the outputs can be diffed directly:
#
# diff docs/output/before-S07DefaultsThatFlipped.txt \
# docs/output/after-S07DefaultsThatFlipped.txt
set -u
cd "$(dirname "$0")"
mvn -B -q clean compile || { echo "compile failed"; exit 1; }
mkdir -p docs/output
FAILED=0
run_module() {
local module="$1" prefix="$2" pkg="$3"
local cp
cp="$module/target/classes:$(cd "$module" && mvn -B -q dependency:build-classpath \
-Dmdep.outputFile=/dev/stdout -DincludeScope=runtime 2>/dev/null | tail -1)"
for f in $(find "$module/src/main/java" -name '*.java' | sort); do
grep -q 'public static void main' "$f" || continue
local short class
short=$(basename "$f" .java)
class="$pkg.$short"
printf '%-14s %-32s' "$prefix" "$short"
if java -cp "$cp" "$class" > "docs/output/$prefix-$short.txt" 2>&1; then
echo "ok"
else
echo "FAILED"; FAILED=1
fi
done
}
run_module jackson2-before before com.ankurm.migration.before
run_module jackson3-after after com.ankurm.migration.after
run_module coexistence coexistence com.ankurm.migration.coexist
echo
echo "--- before/after diffs ---"
for after in docs/output/after-*.txt; do
short=$(basename "$after" .txt); short=${short#after-}
before="docs/output/before-$short.txt"
[ -f "$before" ] || continue
if diff -q "$before" "$after" >/dev/null; then
echo " $short: identical output"
else
echo " $short: differs (expected — that is the migration surface)"
fi
done
echo
if [ "$FAILED" -eq 0 ]; then echo "All examples ran successfully."; else echo "Some examples failed."; fi
exit $FAILED