https://kotlinlang.org logo
#serialization
Title
# serialization
q

qlitzler

12/31/2018, 1:56 AM
Hello, I have this scenario where I need to deserialize a JSON that can have a different type for the same key, depending on a server response I can't control. Example:
Copy code
{ "myKey": true } // First server response
{ "myKey": "someValue" } // Second server response
I don't know in advance what kind of type the value will be, so I came up with this solution. I would like your professional opinion: Is there a better way to do it ? Can it be improved ? If you find it alright, I'm leaving the code snippet for those who might run into the same use case.
v

Vsevolod Tolstopyatov [JB]

01/09/2019, 4:14 PM
Your approach is fine (modulo possible bugs in the implementation)
6 Views