Suppose there is a class with a boolean property, its name starts with is
:
class Preferrable {
var isPreferred: Boolean = true
}
It is serialized to {"preferred":true}
, dropping is
part.
As mentioned in this question, to prevent it, we need to specify property name explicitly, using @JsonProperty("isPreferred")
annotation.
That approach works perfectly with Java. But in case of Kotlin class with annotated property serialized form contains property duplication: {"preferred":true,"isPreferred":true}
.
The workaround is to apply annotation to property getter. It doesn't work for data classes and as for me, this code looks a bit too much for just keeping property name as is:
class Preferrable {
var isPreferred: Boolean = true
@JsonProperty(value = "isPreferred")
get() = field
}
What is the reason behind such behavior? Is it just a bug? Is there a simpler way to prevent is
prefix dropping for Kotlin?