Skip to content
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

Deserialization fails with 'Unrecognized field ...' for a boolean property of a class with a super class with a matching boolean property starting with 'is' #359

Closed
AntipovAndrey opened this issue Aug 19, 2020 · 1 comment
Labels

Comments

@AntipovAndrey
Copy link

Describe the bug
The following code works as expected with 2.9.10 version of the module.

To Reproduce

open class BaseResult(val isSuccess: Boolean)
class DerivedResult(val success: Boolean) : BaseResult(success)

fun main() {
    val json = """
        {
          "success": true
        }
    """.trimIndent()

    val mapper = ObjectMapper()
    mapper.registerModule(KotlinModule())

    assert(mapper.readValue<DerivedResult>(json).success)
}
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "success" (class DerivedResult), not marked as ignorable (one known property: "isSuccess"])
 at [Source: (String)"{
  "success": true
}"; line: 3, column: 2] (through reference chain: DerivedResult["success"])
	at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:855)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1212)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1604)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperties(BeanDeserializerBase.java:1554)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:511)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1322)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:331)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:164)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4524)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3466)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3449)
	at SampleKt.main(Sample.kt:21)

Expected behavior
No failure

Versions
Kotlin: 1.3.72
Jackson-module-kotlin: 2.11.2
Jackson-databind: 2.11.2

Additional context
Caused by #80

@k163377
Copy link
Contributor

k163377 commented Mar 3, 2023

This issue will be fixed by #630 and therefore closed as a duplicate.

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

No branches or pull requests

2 participants