0

I have a data class which has a property named isActive. When it gets returned as json the result is empty, but when I change it to active it works. Is there a way to fix it without changing the name?

When I asked chatgpt it said to use @JsonProperty, I tried that but it doesn't work

data class ResponseResult(
    @JsonProperty("isActive")
    val isActive: String
)
  • 1
    Can you add more info about how you're using this data class? Post your controllers/services etc... – Adel Khial May 09 '23 at 06:11
  • I think this problem is similar: https://stackoverflow.com/questions/45720177/classmapper-no-setter-field-for-abooleantype/72845873#72845873 – Robin May 09 '23 at 06:20
  • post your `ObjectMapper` configuration – Stefan Golubović May 09 '23 at 06:29
  • 1
    Long time since i worked with something similar, but @JsonProperty("isActive") should only define the property name outside your class. Have you tried to use: `@JsonProperty("isActive") val active: String` or does the problem occur with the isActive as a JSON name? – Javatar May 09 '23 at 11:48
  • It's usually conventional for `isXxx` properties to be of type Boolean. (I think that originated with JavaBeans, but Kotlin and Spring both follow those conventions to some extent.) Perhaps the non-Boolean type is confusing Spring? – gidds May 09 '23 at 19:08

0 Answers0