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

2.15.0 does not seem to honor PropertyAccessor.IS_GETTER visibility anymore #3904

Closed
fleiber opened this issue May 1, 2023 · 5 comments
Closed
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@fleiber
Copy link

fleiber commented May 1, 2023

Here is a small main reproducing the behaviour change:

import com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule


fun main() {
    val mapper = ObjectMapper().apply {
        registerModule(KotlinModule.Builder().build())
        setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE)
    }

    class Foo(val bar: Int) {
        val isZero get() = bar == 0
    }

    println(mapper.writeValueAsString(Foo(1)))
    // with Jackson 2.14.2, prints: {"bar":1}
    // with Jackson 2.15.0, prints: {"bar":1,"isZero":false}
}

We serialize these classes with setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE) to ignore the isXXX methods, and please note that we cannot use @JsonIgnore ("This annotation is not applicable to target 'member property without backing field or delegate'").
Starting with Jackson 2.15.0, the isZero property is serialized, then the deserialization fails.
The way we use the visibility feature looks fine to me, this property was correctly ignored at serialization with version 2.14.2, so I would say the 2.15 change does look like a regression.

@fleiber fleiber added the to-evaluate Issue that has been received but not yet evaluated label May 1, 2023
@fleiber fleiber changed the title 2.15.0 does not seem to honor anymore 2.15.0 does not seem to honor PropertyAccessor.IS_GETTER visibility anymore May 1, 2023
@pjfanning
Copy link
Member

Could you move this to the jackson kotlin module? Noone in core jackson team uses Kotlin.

@fleiber
Copy link
Author

fleiber commented May 1, 2023

Could you move this to the jackson kotlin module? Noone in core jackson team uses Kotlin.

As you wish, but I can also edit it to write the same code in Java :)

@pjfanning
Copy link
Member

try a Java example but as long as this remains a Kotlin example, it will probably require us to pass this off to the Kotlin module team to look at

@fleiber
Copy link
Author

fleiber commented May 1, 2023

try a Java example but as long as this remains a Kotlin example, it will probably require us to pass this off to the Kotlin module team to look at

I could not reproduce in Java, and with the cleaner example shown in the updated description, the issue disappears when removing the KotlinModule... Let me close this issue and open a new one in the Kotlin module repo.

jackson-module-kotlin#669

Sorry for the inconvenience,

@fleiber fleiber closed this as completed May 1, 2023
@cowtowncoder
Copy link
Member

@fleiber Thank you for checking this. I think this is related to the nasty incompatibility between Kotlin's handling of "isXxx" properties wrt Java Beans handling. I think Kotlin will retain "is" part for logical property name (as per Kotlin spec, perfectly fine), but that does not necessarily play nicely with databind as the rules are different.
But I hope this can be resolved; I don't know what change (and intentional or unintentional) caused behavior to change between versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

3 participants