Skip to content

Make Jackson waterproof and avoid it failing in native image #1658

@hohwille

Description

@hohwille

Task summary

Issue #1644 was again one of many issues where we implemented some feature using Jackson to deserialize JSON to Java and all was green in Java but failed in GraalVM native image.
My initial plan was to find a way to disable (deep) reflection support in Jackson somehow entirely and force ourselves to always write JsonDeserializers already to make it work in Java.
However, @maybeec had a great idea that seems even better:
In PR #1655 he wrote a JUnit test that tries to find all classes that we deserialize from JSON and checks that they are all listed in reflect-config.json. Currently this test only finds classes that implement JsonObject or JsonVersionItem.
The problem is that there are many other classes affected not found by this condition:

  • Cve
  • ToolSecurity
  • ToolDependency
  • VersionRange
  • VersionIdentifier
  • CustomToolsJson
  • CustomToolJson

Side note: JsonVersionItem is not used by IDEasy itself but only by our UrlUpdaters that always run in JVM.
But since these classes are not inside the cli module, the test would not find them anyhow so it does not harm.
Since JsonObject is only a marker interface, we should derive JsonVersionItem from JsonObject.

My ideas on this:

  • We already have JsonMapping to somehow centralize and wrap our Jackson configuration.
  • We could even wrap Jackson entirely creating our own API to deserialize JSON that only accepts Class<? extends JsonObject>.
  • BTW: Do we need to create separate instances of ObjectMapper or can we share a singleton instance? IMHO it is not stateful and therefore we could simply do that. Then we could even simplify our own code with the "wrapper".
  • Our test can then find at least all root objects that must implement JsonObject.
  • We could find all child objects via refelection by decomposing the root objects.

If that approach turns out way too complex, we could still try to find out if we can disable the generic reflection based deserializer in Jackson what should IMHO be possible or we raise a feature request for that.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestjsonnative-imageGraalVM native image of IDEasy CLI (e.g. for bugs that only happen in binary of CLI)

    Type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions