BollywoodVillain
11/24/2020, 7:00 AM{
"type": "node",
"id": 66917229,
"lat": 52.5167295,
"lon": 13.3797732,
"tags": {
"addr:city": "Berlin",
"addr:housenumber": "4a",
"addr:postcode": "10117",
"addr:street": "Pariser Platz",
"amenity": "cafe",
"brand": "Starbucks",
"name": "Starbucks",
"website": "<https://www.starbucks.de/store-locator/store/2099/pariser-platz-pariser-platz-4-a-berlin-be-10117-de>",
"wheelchair": "yes",
"wifi": "free"
}
}
I am using custom Serializer but I’m a bit lost on how to unwrap the nested values in the deserialize
function for the nested tags element. Any help is highly appreciated.rnett
11/24/2020, 7:26 AMBollywoodVillain
11/24/2020, 7:40 AMIs there a reason you can’t make a class for the nested elements and have it as a parameter?It works as a nested class but I wanted to keep it on a single level to keep it a bit cleaner. I could try with a custom Serializer with a
SerialDescriptor
but I’m not sure how to represent the nested tags
structure. Is there an example that I could follow?
override val descriptor: SerialDescriptor =
buildClassSerialDescriptor("element") {
element<String>("type")
element<String>("id")
// How to represent tags?
element<String>("tags")
element<String>("addr:housenumber")
}
rnett
11/24/2020, 8:05 AMdecodeStructure
and the other decode methods with it inside the section for decoding tagsrnett
11/24/2020, 8:08 AMtags
a Map<String, String>
if everything's a string, or Map<String, JsonElement>
or just a JsonObject
. All of those would be deserialized correctly as far as I know.
You could then just delegate to the map for your properties (i.e. val brand by tags
if it's a Map<String, String>
.BollywoodVillain
11/24/2020, 8:09 AMVampire
11/24/2020, 8:10 AMBollywoodVillain
11/24/2020, 8:12 AMrnett
11/24/2020, 7:33 PM