Problems with no-arg plugin + JsonIgnore + Kotlin 1.1 #61
Description
I tried updating an internal project to Kotlin 1.1, but I encountered an issue with one of our data classes. It seems that in some circumstances deserializing doesn't work even though it worked fine with Kotlin 1.0.6.
I uploaded a minimal example project that demonstrates the error here: https://github.com/mhlz/jackson-module-kotlin-issue
If you change the kotlin.version property in the pom.xml to 1.0.6 it works fine. But with 1.1.0 it crashes with the following exception:
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Could not find creator property with name 'innerTest' (in class Test)
at [Source:
{
"innerTest": {
"str": "str",
"otherStr": "otherStr"
}
}
; line: 2, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270)
at com.fasterxml.jackson.databind.DeserializationContext.reportMappingException(DeserializationContext.java:1234)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:551)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:226)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:141)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:403)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:476)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3899)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3794)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2842)
at MainKt.main(Main.kt:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
I figured out that removing the @field:JsonIgnore annotation makes the exception go away. The same thing happens with @get:JsonIgnore as well.
I hope the example project gives enough info to debug this issue properly, as I have no idea what could cause this problem.
After investigating more this issue does not occur with module-kotlin 2.8.6 and databind 2.8.6. Those work fine with Kotlin 1.1.
Activity
apatrida commentedon Mar 7, 2017
thanks, I'll look at it.
jamesbassett commentedon Mar 10, 2017
We had a similar issue with Kotlin 1.0.6 and Jackson 2.8.7.
@JsonIgnore'd constructor properties were causing all properties to be ignored. We've reverted to Jackson 2.8.6 for now. Interestingly, moving them to normal (non-constructor) properties fixed the issue.apatrida commentedon Mar 24, 2017
@mhlz a side note, in your code you can do:
or
instead of passing
Test::class.javato thereadValue()method. It is a better pattern since it'll reify and catch all generics in the future case where you have a class with generics, best to be in the same pattern.apatrida commentedon Mar 24, 2017
@cowtowncoder this one is odd, the plugin does the same behavior as it has done for a long time, but with databind 2.8.7 it breaks, while in 2.8.6 it works fine. The plugin says that there is a creator annotation on the correct constructor, and has returned the correct name for the parameters including the one that it says is missing. I don't have a java-only reproducible case, but you can debug the above linked project (intellij+kotlin plugin, load pom.xml and debug the databinding code). Kotlin module works at 2.8.6 or 2.8.7 versions, it is only the databind version number change that breaks the process.
apatrida commentedon Mar 24, 2017
@cowtowncoder see FasterXML/jackson-databind#1572
apatrida commentedon Apr 3, 2017
This is fixed in
2.8.8-SNAPSHOTof databind, so closing issue here, track FasterXML/jackson-databind#1572 for release and additional information, but should be fine in 2.8.8 and 2.9.x branch