Nick
08/16/2024, 12:58 AMisMyFeautureEnabled
and when the data class gets serialized, there are two booleans serailzed isMyFeatureEnabled
and a phantom field myFeatureEnabled
(without the is). If I change the name of isMyFeatureEnabled
to something like testFieldName
, then I don't see the phantom field. Anyone come across this before?
So:
data class MyData(
val field1: String,
val field2: String,
val isMyFeautureEnabled: Boolean,
)
serializes to:
{
"field1": "test",
"field2": "test",
"isMyFeatureEnabled": true,
"myFeatureEnabled": true
}
but
data class MyData(
val field1: String,
val field2: String,
val testField: Boolean,
)
serializes to:
{
"field1": "test",
"field2": "test",
"testField": true
}
Not sure if it's a Kotlin thing or a Jackson thing but it must be something to do with the is
in the name.Nick
08/16/2024, 1:22 AM@get:JsonProperty("isMyFeautreEnabled")
annotation on it fixed it.dave
08/16/2024, 6:38 AMKlitos Kyriacou
08/16/2024, 8:06 AMTim Mortimer
08/16/2024, 12:54 PMdave
08/16/2024, 12:56 PMDavid Kubecka
08/16/2024, 12:58 PMdave
08/16/2024, 12:59 PMMervyn McCreight
08/16/2024, 7:40 PMis<PropertyName>
for java-beans as per specification (at least the last time I had a look at it). That is most possibly the reason for jackson to interpret the presence of a function like is<PropertyName>
that returns boolean
as if there was a boolean property with that particular name.
Remember that kotlin autogenerates the function isMyFeatureEnabled()
that returns a boolean for your val, that might be why jackson picks that up.Mervyn McCreight
08/16/2024, 7:42 PM