FasterXML / FasterXML/jackson-module-kotlin

2.15.0 does not seem to honor PropertyAccessor.IS_GETTER visibility anymore

Aperta
#669 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Kotlin
Stelle
1.2k
Fork
187
Merge medio
9h 48m
PR unite (30g)
16

Descrizione

Here is a small main reproducing the behaviour change:
```kt
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 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. Please also note that the issue only appears when we register KotlinModule.

The way we use the visibility feature looks fine to me, the property was correctly ignored at serialization with version 2.14.2, so I would say the 2.15 change does look like a regression.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.