-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPE when transforming a tree to a model class object, at ArrayNode.elements()
#4145
Comments
Java reproduction would be needed, just in case. Or at least full standalone one -- this appears to be code snippet? |
Yes, it is a snippet - I was hoping someone would see right away what the situation is, and the report would thus be useful. The trigger is that the After I coded the tree manipulation properly: val filters: List<SystemData.Ui.AssetMetadataFilter>? = ddbModel.systemData?.ui?.filters
tree.set<ObjectNode>("uiConfig", ObjectNode(factory, mapOf(
"filters" to
if (filters == null) NullNode.instance
else ArrayNode(factory, filters.map { filter ->
Filters(defaultLabel = filter.defaultLabel, path = filter.path, type = filter.type)
.let { jsonMapper.valueToTree<ObjectNode>(it) }
})
))) Now the objectMapper.treeToValue() works. |
Yeah, Kotlin version is pretty dense so it was not obvious to me where |
ArrayNode.elements()
Thank you @OndraZizka: I added null check for both ArrayNode and ObjectNode constructors wrt passing of |
Thanks @cowtowncoder :) |
Search before asking
Describe the bug
When deserializing a tree of
JsonNode
s, Jackson causes a NPE.The ArrayNode where it fails is likely the one created this way in Kotlin:
Which means, in
ArrayNode(..., content)
, the content is null.Version Information
2.15.2
Reproduction
Where
MyModel
would be an appropriate class.Expected behavior
Maybe
ArrayNode
should not accept null as a content?Jackson should fail gracefully, with a proper error message
Optionally, it could just create an empty array node in such situation, for those who prefer robustness over validity.
Additional context
The text was updated successfully, but these errors were encountered: