kevin.cianfarini
11/28/2022, 12:01 AM"divisions": {
(key): {
"name": string,
"alsoKnownAs": [string],
"officeIndices": [unsigned integer]
}
},
I only care about the value of (key)
which is a dynamic string. I was originally deserializing this to a Map<String, String>
but for obvious reasons ran into edge cases when the alsoKnownAs
and officeIndices
fields came back in a response.
Is there a way to deserialize to Any?
if I don't care about the actual value here, only the key?jw
11/28/2022, 12:05 AMjw
11/28/2022, 12:05 AMjw
11/28/2022, 12:06 AMjw
11/28/2022, 12:06 AMephemient
11/28/2022, 12:07 AM...
as long as it's well-formed:
@Serializable data class Structure(
val divisions: Map<String, Unit>
)
val json = Json {
ignoreUnknownKeys = true
}
json.decodeFromString<Structure>(
"""
{
"divisions": {
"foo": { ... },
"bar": { ... }
}
}
"""
)
jw
11/28/2022, 12:08 AMkevin.cianfarini
11/28/2022, 12:10 AM