3

I am going through very strange and small issue. I have one data class which I am using for Json parsing. That data class (Json) has one attribute

val isExpired: Boolean

but after response creation its not taking isExpired as key. It's always changing it to expried.

"expired": false
john
  • 359
  • 1
  • 4
  • 15

3 Answers3

3

Are you using Jackson to do the serialization? If so, then the answer would normally be that you need to annotate the property with @JsonProperty("isExpired"). However in the specific case of Boolean properties it's not quite that, as discussed here. So actually what you need to do here is as follows:

data class MyClass(@get:JsonProperty("isExpired") val isExpired: Boolean)
Yoni Gibbs
  • 6,518
  • 2
  • 24
  • 37
0

Simple answer for simple question

    @get:JsonProperty("isExpired") val isExpired: Boolean
john
  • 359
  • 1
  • 4
  • 15
0

This is fixed in jackson-module-kotlin 2.10 https://github.com/FasterXML/jackson-module-kotlin/pull/256

Prateek
  • 6,644
  • 6
  • 22
  • 26