Davide Giuseppe Farella
11/03/2020, 8:33 AMtype
, we implemented the model with `sealed class`; serialization works flawlessly, but deserialization doesn’t include the field type
. What is the best way to deal with it? We’re on 1.4.10Igor Brishkoski
11/03/2020, 1:45 PMsealed class Response {
class Success() : Response()
}
val r: Response = Success(data)
val jsonString = Json.encode(r)
val r: Response = Json.decode("json with type")
Davide Giuseppe Farella
11/03/2020, 4:13 PMJson.encode(myClass)
, the type
field is skipped ( not in the generated String )Paul Griffith
11/03/2020, 4:21 PMPaul Griffith
11/03/2020, 4:22 PMIgor Brishkoski
11/03/2020, 4:26 PMval r: Response
with val r: Success
json will not add the type
field. Idk if that's how it supposed to work or it's a bug.
with val r: Response
you get { type: Success, data: int}
with val r: Success
you get { data: int}
Igor Brishkoski
11/03/2020, 4:28 PMtype
key to be anything, instead of type
it can be pet
and {pet: Dog, data: name}
Paul Griffith
11/03/2020, 4:32 PMDavide Giuseppe Farella
11/03/2020, 4:41 PM