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

Tomas Kormanak

10/02/2020, 9:52 AM
Hi, is there a way how to deserialize dynamic structure from JSON? For example I have this class but I don't know the exact structure of
data
property.
Copy code
@Serializable
data class Sample(
    val name:String,
    val data: Any
)
j

Jérôme Gully

10/02/2020, 1:05 PM
I don't know if it's what you search, but you can try to use JsonElement :
Copy code
Json.parseToJsonElement(sample).jsonObject["data"]
https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json.md#json-elements
2 Views