Skip to content

Problems with no-arg plugin + JsonIgnore + Kotlin 1.1 #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mhlz opened this issue Mar 7, 2017 · 6 comments
Closed

Problems with no-arg plugin + JsonIgnore + Kotlin 1.1 #61

mhlz opened this issue Mar 7, 2017 · 6 comments

Comments

@mhlz
Copy link

mhlz commented Mar 7, 2017

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.

@apatrida
Copy link
Member

apatrida commented Mar 7, 2017

thanks, I'll look at it.

@jamesbassett
Copy link

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
Copy link
Member

@mhlz a side note, in your code you can do:

 val test: Test = mapper.readValue(testJson)

or

 val test = mapper.readValue<Test>(testJson)

instead of passing Test::class.java to the readValue() 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
Copy link
Member

@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
Copy link
Member

@apatrida
Copy link
Member

apatrida commented Apr 3, 2017

This is fixed in 2.8.8-SNAPSHOT of 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

@apatrida apatrida closed this as completed Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants