You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When attempting to serialize a Kotlin data class which has a property prefixed with "is", but not a boolean, Jackson will ignore the property.
Version information
Tested on jackson-databind:2.13.1
To Reproduce
If you have a way to reproduce this with:
In a Kotlin project, create a dummy data class with a field that is not a boolean but is prefixed with is.
Create a Jackson object mapper and attempt to write the object to a string.
The property prefixed with is will be ignored.
For example, the following snippet is self-contained:
importcom.fasterxml.jackson.module.kotlin.jacksonObjectMapperdata classPerson(
valname:String,
valisAlive:Int,
valisDead:Boolean,
)
funmain() {
val mapper = jacksonObjectMapper()
val actual = mapper.writeValueAsString(Person("Dave", 0, true))
val expected ="""{"name":"Dave","isAlive":0,"isDead":true}"""assert(expected == actual) { "Expected $expected but got $actual." }
}
Produces
Exception in thread "main" java.lang.AssertionError: Expected {"name":"Dave","isAlive":0,"isDead":true} but got {"name":"Dave","isDead":true}.
Expected behavior
All three properties should be included, but the produced output is {"name":"Dave","isDead":true}, with the isAlive property ignored.
Additional context
I am unfamiliar with the internals of Jackson but I've found the following two pieces of information that might be helpful:
When looking at the generated bytecode, Kotlin generates a getter named isAlive for the integer property, instead of getIsAlive which might be expected by Jackson. Manually adding in a getter of that format to the class (fun getIsAlive() = isAlive) fixes the wrong behavior.
In BeanSerializerFactory.java, on line 595, properties correctly contains all three properties, but these are then removed by the call to removeIgnorableTypes, since property.getAccessor() on line 763 returns null for the offending property. I did not investigate further to see how the getters in POJOPropertyBuilder are computed, so I am unsure what the root cause is.
The text was updated successfully, but these errors were encountered:
I verified on branch 2.15 and the submitted test case seems to be fixed.
This is probably a duplicate of #340, which appears to have been fixed in #641.
Describe the bug
When attempting to serialize a Kotlin data class which has a property prefixed with "is", but not a boolean, Jackson will ignore the property.
Version information
Tested on jackson-databind:2.13.1
To Reproduce
If you have a way to reproduce this with:
is
.is
will be ignored.For example, the following snippet is self-contained:
Produces
Expected behavior
All three properties should be included, but the produced output is
{"name":"Dave","isDead":true}
, with theisAlive
property ignored.Additional context
I am unfamiliar with the internals of Jackson but I've found the following two pieces of information that might be helpful:
isAlive
for the integer property, instead ofgetIsAlive
which might be expected by Jackson. Manually adding in a getter of that format to the class (fun getIsAlive() = isAlive
) fixes the wrong behavior.BeanSerializerFactory.java
, on line 595,properties
correctly contains all three properties, but these are then removed by the call toremoveIgnorableTypes
, sinceproperty.getAccessor()
on line 763 returns null for the offending property. I did not investigate further to see how the getters inPOJOPropertyBuilder
are computed, so I am unsure what the root cause is.The text was updated successfully, but these errors were encountered: