NullNode injected when instantiating data class with nullable property
See original GitHub issueFollowing tests fails:
class Test {
data class MyData(val value: JsonNode?)
@Test
fun testNullValue() {
val mapper = ObjectMapper()
mapper.registerModule(KotlinModule())
val json = "{\"value\": null}"
val actual: MyData = mapper.readValue(json, MyData::class.java)
val expected = MyData(null)
Assert.assertEquals(expected, actual)
}
@Test
fun testMissingProperty() {
val mapper = ObjectMapper()
mapper.registerModule(KotlinModule())
val json = "{}"
val actual: MyData = mapper.readValue(json, MyData::class.java)
val expected = MyData(null)
Assert.assertEquals(expected, actual)
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Distinguish null from missing properties in Jackson using ...
I have a large domain model (50+ classes) built almost entirely out of Kotlin data classes. Kotlin's data classes provide a lot of...
Read more >Hibernate Validator 8.0.0.Final - Jakarta Bean Validation ...
Validating data is a common task that occurs throughout all application layers, from the presentation to the persistence layer.
Read more >Index (jackson-databind 2.9.0.pr4 API) - Javadoc.io
Simple value classes that contain definitions of properties, used during introspection of properties to use for serialization and deserialization purposes.
Read more >Constructor parameter default value when receiving null input ...
But I'm not sure if it should be really allowed on data classes. ... and requires that the consumer specifically instantiate that mapper, ......
Read more >Serialized Form - Red Hat Customer Portal
May be an interface or abstract class, so instantiation may not be possible. ... If null, a new instance is created, if non-null,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I will move this to
jackson-databind
since there is Java-only reproduction.I can not say off-hand if I’d considered it a bug or not: problem is that “null value” for type of
JsonNode
makes sense to beNullNode
in many use cases. But I will see if it is possible to distinguish these cases from “empty value” handling.Agreed. Documentation is a big challenge. But there may also be semantic component, as
JsonNode
is not (or I don’t think of it as) quite same “reference type” asOptional
. I can see this going either way.On documentation, I suppose this is in area of “null handling”, in a way. But more generally there probably should be some sort of table for various Features for different Java types, their general handling. My biggest problem is usually that of getting started, creating structure for documentation: it is easier to fill in structure with more information, incrementally, than come up with a good structure to start.
Another related challenge is that much of this is controlled in decentralized manner, basically by
JsonSerializer
/JsonDeserializer
implementing certain handlers.