FasterXML / jackson-module-kotlin

Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Apache License 2.0
1.12k stars 175 forks source link

com.fasterxml.jackson.databind.JsonMappingException: lateinit property value has not been initialized #731

Open asqatqazet opened 9 months ago

asqatqazet commented 9 months ago

Search before asking

Describe the bug

I was serializing an object into xml and the object is read from xml as well, so some value declared as lateinit might be missing and not initializedd. from my opionion, this values can be leaved as null or empty if it is not initialized rather than throwing exception and not being able to progress.

To Reproduce

// Your code here
How the mapper is nitialized: 
   val xmlMapper = XmlMapper.builder()
            .defaultUseWrapper(false)
            .configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true)
            .configure(ToXmlGenerator.Feature.UNWRAP_ROOT_OBJECT_NODE, true)
            .build()
            .registerKotlinModule()

How my lateinit value is declared: 

    @field:JacksonXmlText
    lateinit var value: String private set

and there is builtin feature in kotlin to determine whether the value is initialized:

    fun isValueInitialized(): Boolean {
        return ::value.isInitialized
    }

Expected behavior

No response

Versions

Kotlin: Jackson-module-kotlin: Jackson-databind:

Additional context

No response

cowtowncoder commented 9 months ago

I assume the issue is not really XML related? If so, would be nice to get JSON reproduction, instead of XML one.