Upgrade to Jackson 3#556
Conversation
* 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
| for (JsonNode arrayItem : node) { | ||
| if (arrayItem.isNull()) { | ||
| return null; | ||
| } | ||
| result.add(arrayItem.asString()); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
}
}|
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 |
|
Thanks @filiphr for doing the heavy lifting here. 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. |
|
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, |
|
Hi @filiphr That'd be greatly appreciated. Assuming you have some experience with the latest GitHub Actions, I'd gladly leave that to you. |
com.fasterxml.jackson.databindandcom.fasterxml.jackson.coretotools.jackson.databindandtools.jackson.corecom.networknt:json-schema-validatorto 3.0.0 (Jackson 3 support)isString/asString/stringValueinstead ofisTextual/asText/textValueStringNodeinstead ofTextNodeJsonMapper#sharedinstead of underlying Schema ConfigObjectMapperinSubtypeResolutionSimpleIntegrationTestsince schema validation requires numbers, but underlying Object Mapper uses strings for numbersThis is for #553