Reputation: 755
I have serialised the data class model "ProfileInfo" using
val jsonString = jacksonObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE).writeValueAsString(profileInfo)
but when I deserialise the jsonString into data class model using
val profileInfo: ProfileInfo = jacksonObjectMapper().readValue<ProfileInfo>(jsonString)
only the fields without underscores receiving the value. other fields with underscores assigned as null. Could anybody help me about how to deserialise using Jackson object mapper.
Upvotes: 3
Views: 4154
Reputation: 10681
Each call to the jacksonObjectMapper()
creates a new ObjectMapper
, so either:
val mapper = jacksonObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
val jsonString = mapper.writeValueAsString(profileInfo)
...
val profileInfo: ProfileInfo = mapper.readValue(jsonString)
val profileInfo: ProfileInfo = jacksonObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE).readValue(jsonString)
Upvotes: 3