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

Nikky

09/10/2018, 10:27 PM
seems like JSON does not support
writeStringElementValue
or similar, i hoped to be able to use the infrastructure to support writing customized JSON objects
s

sandwwraith

09/11/2018, 10:16 AM
what do you mean by ‘not support’?
if you want to write a custom serializer with code to similar what plugin generates, you can look for a hint here: https://github.com/Kotlin/kotlinx.serialization/blob/master/runtime/common/src/test/kotlin/kotlinx/serialization/CustomSerializersTest.kt#L51 It even has the feature you want – ignore default value
👍 1
n

Nikky

09/11/2018, 12:19 PM
i think i get it now, i did that without writeBegin and writeEnd
one more questions.. do indices indicate the positioning in the resulting json ?
s

sandwwraith

09/11/2018, 1:14 PM
theirs main purpose is to indicate position in Kotlin class definition, to be able to retrieve name for them. Resulting json will be formed in order you’ve made
writexxxElement
calls.
n

Nikky

09/11/2018, 2:52 PM
in the example you show that you can skip them with a if .. does that work always ? i have ~20 variables that i want to to skip serializin when they are their default value
3 Views