Thread
#serialization
    pablisco

    pablisco

    3 years ago
    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

    sandwwraith

    3 years ago
    you can get current index, and then map it using method of
    KSerialClassDesc
    . It is equal to property name by default.
    pablisco

    pablisco

    3 years ago
    But that's order dependent right?
    s

    sandwwraith

    3 years ago
    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.
    pablisco

    pablisco

    3 years ago
    Since I've got you here 🙂 what's the best way to parse a field that depends on information from another?
    s

    sandwwraith

    3 years ago
    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
    pablisco

    pablisco

    3 years ago
    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.