Repository navigation
feat: migrate to Jackson 3 - #385
GabrielBBaldez wants to merge 4 commits into
Conversation
Migrates the SDK from Jackson 2.17.3 to Jackson 3.0.0. Closes crowdin#370. - build.gradle: use the tools.jackson BOM (jackson-databind 3.0.0); jackson-annotations stays on com.fasterxml.jackson per Jackson 3 - imports moved from com.fasterxml.jackson.{core,databind} to tools.jackson.* (annotations package unchanged) - JacksonJsonTransformer: ObjectMapper is immutable in 3.x, rebuilt via JsonMapper.builder() (configure, changeDefaultPropertyInclusion(NON_NULL), defaultDateFormat, addModule, changeDefaultVisibility); derived mappers via rebuild() - custom (de)serializers ported: JsonSerializer/JsonDeserializer -> ValueSerializer/ValueDeserializer, SerializerProvider -> SerializationContext, ContextualDeserializer removed (createContextual now declared on ValueDeserializer), p.getCodec().readTree(p) -> ctxt.readTree(p), getCurrentToken() -> currentToken(), node.fieldNames() -> propertyNames(), exceptions are unchecked (dropped throws IOException) - tests: rewrote the deserializer unit tests that relied on removed Jackson 2 internals (JsonParser.setCodec, ObjectMapper.getFactory/getDeserializationContext) to drive deserialization through a configured mapper BREAKING CHANGE: now requires Jackson 3 (tools.jackson coordinates). Jackson 3's StdDateFormat serializes UTC dates as "...Z" (canonical ISO-8601) instead of "...+00:00"; the affected request fixture was updated accordingly. All 579 tests pass.
- Jackson 3 requires Java 17, so bump sourceCompatibility to 17 and the CI workflows (basic.yml, docs.yml) to Java 17. This drops Java 8/11 support, which is an inherent consequence of Jackson 3. - remove 'import lombok.var;' (HttpException, Sandbox, CrowdinApiTest); native var (Java 10+) replaces it.
JaCoCo 0.8.5 cannot read Java 17 class files (major version 61), failing jacocoTestReport. Bump to 0.8.11, which supports Java 17/21.
andrii-bodnar
left a comment
There was a problem hiding this comment.
@GabrielBBaldez thank you for the contribution! My main concern here is the Java 8/11 drop - moving to a Java 17 is a breaking change.
Some users still on Java 8/11 could be affected by moving to a Java 17, so unless there's a real driver to adopt Jackson 3 now, this needs to ship as a major version (2.0.0).
| assertThrows(NullPointerException.class, () -> deserializer.deserialize(jsonParser, deserializationContext)); | ||
| assertThrows(Exception.class, () -> mapper.readValue(json, FileFormatSettingsResource.class)); |
There was a problem hiding this comment.
This loosens the assertion from NullPointerException to Exception, so it'll now pass on any failure
| import tools.jackson.databind.ValueDeserializer; | ||
| import tools.jackson.databind.ObjectMapper; | ||
|
|
||
| import java.io.IOException; |
There was a problem hiding this comment.
Leftover import now that the method no longer throws IOException. Same pattern across the other deserializers, plus the unused tools.jackson.core.JacksonException imports
|
Totally fair. The Java 17 floor comes from Jackson 3 itself (the 3.x line requires JDK 17 as its baseline), so there's no way to adopt it without raising the project's baseline — it's inherently a breaking change. |
…st assertion - Remove leftover java.io.IOException imports (methods no longer throw it in Jackson 3) and unused tools.jackson.core.JacksonException imports across the json deserializers. - Restore the FileFormatSettingsDeserializerTest assertion to NullPointerException instead of the loosened Exception: Jackson 3 propagates the NPE from the missing settings node unwrapped, so the specific assertion holds.
|
Addressed both review points:
|

Purpose
Migrates the SDK from Jackson 2.17.3 to Jackson 3.0.0, as requested in #370.
What changed
build.gradle: switched to thetools.jacksonBOM (jackson-databind3.0.0).jackson-annotationsintentionally stays undercom.fasterxml.jackson(Jackson 3 keeps the annotations package).sourceCompatibilitybumped 8 → 17 and the CI workflows (basic.yml,docs.yml) bumped to Java 17 (Jackson 3's minimum). Removedimport lombok.var;(3 files) in favor of nativevar.com.fasterxml.jackson.{core,databind}.*→tools.jackson.*(annotations untouched;JsonFactorymoved totools.jackson.core.json).JacksonJsonTransformer:ObjectMapperis immutable in 3.x, so the mapper is built withJsonMapper.builder()(configure,changeDefaultPropertyInclusion(NON_NULL),defaultDateFormat,addModule,changeDefaultVisibility); derived mappers userebuild()instead ofcopy().JsonSerializer/JsonDeserializer→ValueSerializer/ValueDeserializerSerializerProvider→SerializationContextContextualDeserializerremoved —createContextualis now declared onValueDeserializerp.getCodec().readTree(p)→ctxt.readTree(p);getCurrentToken()→currentToken();node.fieldNames()→propertyNames()throws IOException(Jackson exceptions are unchecked in 3.x)JsonParser.setCodec,ObjectMapper.getFactory,ObjectMapper.getDeserializationContext). They were rewritten to drive deserialization through a configured mapper (readValue), preserving the same assertions.Heads-up (behavioral change)
Jackson 3's
StdDateFormatserializes UTC dates as...Z(canonical ISO-8601) instead of...+00:00. For example2019-09-23T11:26:54.000+00:00→2019-09-23T11:26:54.000Z. The affected request fixture was updated. There is no built-in option in Jackson 3'sStdDateFormatto restore the+00:00form; both are valid ISO-8601.Testing
All 579 tests pass locally (
./gradlew test, JDK 17).This is a breaking change (requires Java 17, new
tools.jacksoncoordinates, and the date-format note above), so it's presumably for the next major release — happy to align on timing/approach.Closes #370