ursus
01/28/2025, 3:19 AMlistOf(
Person(
name = "foo",
age = 44,
fooBar = "lol",
isImportant = true,
isNew = true
)
)
Why does this get serialized into json as [{"id":null,"name":"foo","age":44,"fooBar":"lol","new":true,"important":true}]
?
I.e. missing the is
prefixes?
What's even worse is when I try to deserialize the same json that was just serialized, I'll get errors.
Broken by defaultthanksforallthefish
01/28/2025, 7:18 AMisXXX
is the default getter method name for boolean (thanks Jakub, stealing your edit), it should work with
listOf(
Person(
name = "foo",
age = 44,
fooBar = "lol",
important = true,
new = true
)
)
kqr
01/28/2025, 7:18 AMthanksforallthefish
01/28/2025, 7:28 AMObjectMapper
configuration, how are you creating it @ursus? if you have something like
@Bean
fun objectMapper() = ObjectMapper()
you should amend that; my personal preference is to configure the mapper spring already creates for you, if you prefer to create a new one ensure kotlin module is configured
@Bean
fun objectMapper() = ObjectMapper().findAndRegisterModule()
/* or, but I prefer the above one since jackson will scan your classpath and is smart to configure what it needs
@Bean
fun objectMapper() = jacksonObjectMapper() //this is a kotlin extension funtion
*/
with a "correct" object mapper, isImportant
and isNew
work as you expect