Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin is not taking "is" as start of json key

Tags:

json

key

kotlin

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
like image 243
jhon Avatar asked Jan 30 '26 23:01

jhon


1 Answers

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)
like image 184
Yoni Gibbs Avatar answered Feb 01 '26 20:02

Yoni Gibbs