question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullNode injected when instantiating data class with nullable property

See original GitHub issue

Following 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:open
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Apr 30, 2020

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 be NullNode in many use cases. But I will see if it is possible to distinguish these cases from “empty value” handling.

0reactions
cowtowncodercommented, Apr 30, 2020

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” as Optional. 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found