Hello. I’m trying to encode a data class this way:
Json.encodeToString(RequestData.serializer(), requestData)
But in the result I got only changed variables and it doesn’t include all available vars (or vals)
val requestData = RequestData(page = 1, page_size = 2)
requestData.page = 3
Result
Expected : {"page":3, "page_size":2}
Actual : {"page":3}
Also within the constructor it uses only variables from static classes:
@Serializable
data class RequestData(
var page: Int = 1, // will NOT be used
var page_size: Int = MAX_PAGE_SIZE // will be used
var range: Range? = Range("2", "3") // not used
){
@Serializable
data class Range(
var from: String,
var to: String
)
}
And I’m not sure why.
Found same case here