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

Nikky

10/06/2018, 5:20 PM
i have a annoying api where a timestamp can be a string or a long, is there a way to tell in the deserializer what JSON type a field is ? number literal or string literal or is ther tryParseLong() or similar ?
s

sandwwraith

10/07/2018, 3:58 PM
You can create custom serializer for that type and in
deserialize()
cast deserializer to JSONReader to read your value as raw json element: https://github.com/kotlin/kotlinx.serialization/blob/eap13/runtime/jvm/src/test/kotlin/kotlinx/serialization/formats/json/JsonTreeAndMapperTest.kt#L40
2 Views