I have a Kotlin data class that looks like this:
data class SomeData( private val notInJson: String = "some default value", private val inJson: String )
and json string, I want to deserialize an instance of this class -
{ "inJson" : "value" }
When I try to deserialize this data, I get an error that the notInJson
parameter cannot be null. It seems that Jackson is passing him a null value, as he is missing from the json string.
Is there a way for Jackson to not pass any value for him so that you can use the default value specified in the class definition?
- EDIT -
I am registering KotlinModule () with mapper. Using version 2.7.8 or all jackson packages.
The following code is
@Test fun jackson_kotlin_module() { val mapper = ObjectMapper().registerModule(KotlinModule()) println( mapper.readValue("""{ "inJson" : "some value" }""", SomeData::class.java)) }
gives me -
com.fasterxml.jackson.databind.JsonMappingException: Instantiation of [simple type, class SomeData] value failed (java.lang.IllegalArgumentException): Parameter specified as non-null is null: method SomeData.<init>, parameter notInJson at [Source: { "inJson" : "some value" }; line: 1, column: 27]
source share