Another kinda related question. Is there a way to ...
# serialization
p
Another kinda related question. Is there a way to get the name of the current element from the KInput? I guess this may only apply to JSON though.
s
you can get current index, and then map it using method of
KSerialClassDesc
. It is equal to property name by default.
p
But that's order dependent right?
s
Dependent on order inside class declaration in source file. JSON parser will determine current element even if they’re out-of-order in JSON and return correct index.
p
Since I've got you here 🙂 what's the best way to parse a field that depends on information from another?
s
You can try something like this https://github.com/Kotlin/kotlinx.serialization/blob/master/runtime/jvm/src/test/kotlin/kotlinx/serialization/formats/json/JsonTreeAndMapperTest.kt#L35 , or if you don’t want to be tied to JSON, just write a custom serializer and home that independent element would go first, so you can make a right decision when dependent index would be encountered
p
The Json input casting sounds like what I was thinking that I would need. What's the second option? I'm already doing a custom serialiser.