pajatopmr

    pajatopmr

    1 year ago
    A more general statement of my previous question for dealing with the Language Server Protocol (LSP) might be: when encountering a single JSON element (same name == "fieldName") that can be a primitive (
    "fieldName":234
    ), a structure (
    "fieldName":{...}
    ) or an array (
    "fieldName":["string1","string2","string3"]
    ), what is the most logical/appropriate KSX feature for handling the serialization of that JSON element. JsonContentPolymorphicSerializer has proven to be very helpful for "regular" TypeScript <-> Kotlin interface mappings, i.e. interface constructs that appear nearly the same in both languages. It is when TypeScript can have one of primitive, object and/or array JSON elements that it gets much harder, at least as I understand KSX so far. My current thinking is that the most likely feature to use is the experimental one ("Under the hood") in the Json Transformations in the fifth chapter of the Kotlin Serialization Guide. If there is an easier approach, I'd love to hear about it.
    Nikky

    Nikky

    1 year ago
    afaik
    JsonTransformingSerializer
    is the best option you have, i would probably combine it with https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#custom-serializers-for-a-generic-type
    pajatopmr

    pajatopmr

    1 year ago
    This was a good call and much appreciated. I did have to use both JsonTransformingSerializer and JsonContentPolymorphicSerializer and getting them in the right sequence was tricky.