Skip to content

Upgrade to Jackson 3#556

Merged
CarstenWickner merged 3 commits into
victools:mainfrom
filiphr:jackson-3
Dec 30, 2025
Merged

Upgrade to Jackson 3#556
CarstenWickner merged 3 commits into
victools:mainfrom
filiphr:jackson-3

Conversation

@filiphr

@filiphr filiphr commented Dec 27, 2025

Copy link
Copy Markdown
Contributor
  • Change imports for com.fasterxml.jackson.databind and com.fasterxml.jackson.core to tools.jackson.databind and tools.jackson.core
  • Upgrade com.networknt:json-schema-validator to 3.0.0 (Jackson 3 support)
  • Adjust Jackson 2 iterators to Jackson 3 collections
  • Use non-deprecated isString / asString / stringValue instead of isTextual / asText / textValue
  • Use StringNode instead of TextNode
  • Use JsonMapper#shared instead of underlying Schema Config ObjectMapper in SubtypeResolutionSimpleIntegrationTest since schema validation requires numbers, but underlying Object Mapper uses strings for numbers

This is for #553

* Change imports for `com.fasterxml.jackson.databind` and `com.fasterxml.jackson.core` to `tools.jackson.databind` and `tools.jackson.core`
* Upgrade `com.networknt:json-schema-validator` to 3.0.0 (Jackson 3 support)
* Adjust Jackson 2 iterators to Jackson 3 collections
* Use non-deprecated `isString` / `asString` / `stringValue` instead of `isTextual` / `asText` / `textValue`
* Use `StringNode` instead of `TextNode`
* Use `JsonMapper#shared` instead of underlying Schema Config `ObjectMapper` in `SubtypeResolutionSimpleIntegrationTest` since schema validation requires numbers, but underlying Object Mapper uses strings for numbers
Comment on lines +507 to +511
for (JsonNode arrayItem : node) {
if (arrayItem.isNull()) {
return null;
}
result.add(arrayItem.asString());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change here is due to FasterXML/jackson-databind#5417. Looking at the code I assume that if the array node contained null the method would return null as well. In Jackson 3 using arrayItem.asText(null) with a NullNode is going to return the empty string. Therefore, we do a check on isNull instead of using asText(null)

String jsonInstance = JsonMapper.shared().writeValueAsString(new TestClassForSubtypeResolution());

Set<ValidationMessage> validationResult = schemaForValidation.validate(config.getObjectMapper().readTree(jsonInstance));
List<Error> validationResult = schemaForValidation.validate(JsonMapper.shared().readTree(jsonInstance));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this to use JsonMapper.shared(), because the object mapper from the config has JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS. This leads to generating

{
  "supertypeA" : {
    "@type" : "SubClassA",
    "aProperty" : "a"
  },
  "supertypeB" : {
    "@type" : "SubClassB",
    "bProperty" : "98"
  }
}

In the schema for TestSubClassB the bProperty is expected to be integer.

For some reason with Jackson 2 and the way the default ObjectMapper is created the generated JSON is

{
  "supertypeA" : {
    "@type" : "SubClassA",
    "aProperty" : "a"
  },
  "supertypeB" : {
    "@type" : "SubClassB",
    "bProperty" : 98
  }
}

@filiphr

filiphr commented Dec 29, 2025

Copy link
Copy Markdown
Contributor Author

I didn't realize that the project is Java 8 baseline. As part of this commit I also upgraded the baseline to Java 17. If it is preferred, I can do that as part of a separate PR

@CarstenWickner

Copy link
Copy Markdown
Member

Thanks @filiphr for doing the heavy lifting here.
Since the various tests appear to be successful, I'm confident you've covered all important aspects.

I'll try to get Java 21 as a secondary branch build environment up and running, now that Java 11 is no longer in the mix.

@CarstenWickner CarstenWickner merged commit d96e071 into victools:main Dec 30, 2025
2 checks passed
@filiphr

filiphr commented Dec 30, 2025

Copy link
Copy Markdown
Contributor Author

Thanks a lot @CarstenWickner. I was happy to help.

I also wanted to do another PR updating to the latest GitHub Actions and also do Java 21. BTW, there would be some failures on Java 21 I think, BigDecimal has a field named hash now, so one of the tests would fail

@CarstenWickner

Copy link
Copy Markdown
Member

Hi @filiphr

That'd be greatly appreciated. Assuming you have some experience with the latest GitHub Actions, I'd gladly leave that to you.
I'm currently just updating various other dependencies (to make use of the major version upgrade).

@filiphr filiphr deleted the jackson-3 branch January 6, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants