crowdin-api-client-java icon indicating copy to clipboard operation
crowdin-api-client-java copied to clipboard

feat: migrate to Jackson 3

Open GabrielBBaldez opened this issue 5 months ago • 4 comments

Purpose

Migrates the SDK from Jackson 2.17.3 to Jackson 3.0.0, as requested in #370.

⚠️ Jackson 3 requires Java 17. This PR therefore bumps the project baseline from Java 8 to Java 17 (build.gradle + CI workflows), which drops Java 8/11 support. That is an inherent consequence of Jackson 3 and a release-level decision — flagging it explicitly.

What changed

  • build.gradle: switched to the tools.jackson BOM (jackson-databind 3.0.0). jackson-annotations intentionally stays under com.fasterxml.jackson (Jackson 3 keeps the annotations package).
  • Java baseline → 17: sourceCompatibility bumped 8 → 17 and the CI workflows (basic.yml, docs.yml) bumped to Java 17 (Jackson 3's minimum). Removed import lombok.var; (3 files) in favor of native var.
  • Imports: com.fasterxml.jackson.{core,databind}.* → tools.jackson.* (annotations untouched; JsonFactory moved to tools.jackson.core.json).
  • JacksonJsonTransformer: ObjectMapper is immutable in 3.x, so the mapper is built with JsonMapper.builder() (configure, changeDefaultPropertyInclusion(NON_NULL), defaultDateFormat, addModule, changeDefaultVisibility); derived mappers use rebuild() instead of copy().
  • Custom (de)serializers:
    • JsonSerializer/JsonDeserializer → ValueSerializer/ValueDeserializer
    • SerializerProvider → SerializationContext
    • ContextualDeserializer removed — createContextual is now declared on ValueDeserializer
    • p.getCodec().readTree(p) → ctxt.readTree(p); getCurrentToken() → currentToken(); node.fieldNames() → propertyNames()
    • dropped throws IOException (Jackson exceptions are unchecked in 3.x)
  • Tests: the deserializer unit tests relied on Jackson 2 internals that were removed 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 StdDateFormat serializes UTC dates as ...Z (canonical ISO-8601) instead of ...+00:00. For example 2019-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's StdDateFormat to restore the +00:00 form; 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.jackson coordinates, and the date-format note above), so it's presumably for the next major release — happy to align on timing/approach.

Closes #370

GabrielBBaldez avatar Jun 09 '26 16:06 GabrielBBaldez

Heads-up on the build failure — it turned out to be the key point of this migration: Jackson 3 requires Java 17, but the project currently compiles with Java 8 (basic.yml) and build.gradle had sourceCompatibility = 8. So the build couldn't even read Jackson 3's class files (error: cannot access tools.jackson.databind.annotation.JsonDeserialize).

I pushed the necessary follow-up:

  • bumped sourceCompatibility to 17 and the CI workflows (basic.yml, docs.yml) to Java 17;
  • removed import lombok.var; (in HttpException, Sandbox, CrowdinApiTest) — native var (Java 10+) replaces it.

So migrating to Jackson 3 inherently requires Java 17 and drops Java 8/11 support. That's a release-level decision rather than something this PR can avoid — flagging it explicitly so you can decide whether it fits the intended target release. All 579 tests pass locally on JDK 17.

GabrielBBaldez avatar Jun 09 '26 17:06 GabrielBBaldez

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.

GabrielBBaldez avatar Jun 10 '26 13:06 GabrielBBaldez

Addressed both review points:

  • Removed the leftover java.io.IOException imports across the json (de)serializers (12 files) and the unused tools.jackson.core.JacksonException imports (6 files).
  • Restored the FileFormatSettingsDeserializerTest assertion to NullPointerException — verified Jackson 3 propagates the NPE from the missing settings node unwrapped, so the specific assertion holds. Full suite still green locally.

GabrielBBaldez avatar Jun 10 '26 13:06 GabrielBBaldez

Thanks for the update, @GabrielBBaldez - all looks good.

We'd like to hold off on v2.0.0 for now. A major bump is a one-way door, and Jackson 3 / the Java 17 jump alone isn't a strong enough reason yet - Jackson 2.17.x is still fully supported. I'll keep this PR open for the 2.0.0 milestone and fold it in once more breaking changes justify the release. Effort won't go to waste - appreciate it!

andrii-bodnar avatar Jun 10 '26 14:06 andrii-bodnar