FasterXML/jackson-module-kotlin

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

Opened this issue · 1 comments

Search before asking

  • I searched in the issues and found nothing similar.

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

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