Fudge
08/19/2019, 10:37 AMsandwwraith
08/19/2019, 11:39 AMFudge
08/19/2019, 11:51 AMdecodeX
after allFudge
08/19/2019, 12:14 PMNamedValueDecoder
if that matterssandwwraith
08/19/2019, 12:24 PMdecodeElementIndex
which is used to determine current property in stream. Then, deserializer uses this index to call correctly typed decodeX
function. Therefore, if you return from decodeElementIndex
indices, say, 1 and 3, deserializer would be able to infer that the property 2 is missing and use its default valueFudge
08/19/2019, 12:25 PMFudge
08/20/2019, 10:51 AMMap<String, Primitive>
.
When decoding primitives implementing decodeElementIndex
is simple enough because I can just do something like this:
override fun decodeElementIndex(desc: SerialDescriptor): Int {
while (position < desc.elementsCount) {
val name = desc.getTag(position++)
if (name in map.keys) {
return position - 1
}
}
return CompositeDecoder.READ_DONE
}
This doesn't work for non-primitives.
The problem is that structures like lists and nested objects encode using some fairly arbitrary format, like instead of having in a primitive
"MyPrimitive" -> 1
They encode like this
"MyList.size" -> 2
"MyList.1" -> 10
"MyList.2" -> 5
So, I could handle this case manually, check for size etc, but I'm thinking it's not practical to do for every serializer that might serialize like this.
Is there some helper I can use for this? Perhaps an example implementation?sandwwraith
08/20/2019, 11:20 AMsandwwraith
08/20/2019, 11:20 AMTreeJsonInput.kt
sandwwraith
08/20/2019, 11:21 AMNamedValueDecoder
which switches between different implementation if currents structure either a map, a list, or an object