Thread
#serialization
    turansky

    turansky

    3 years ago
    JSON
    {
      "data": [
        {
          "id": "x1_1",
          "type": "x1"
        },
        {
          "id": "x2_1",
          "type": "x2",
          "children": [
            {
              "id": "y1_1",
              "type": "y1"
            },
            {
              "id": "y2_1",
              "type": "y2",
              "connectedItems": [
                "x1_1"
              ]
            }      
        }
      ]
    }
    Data classes
    interface X {
      val id: String
    }
    
    interface Y {
      val id: String
    }
    
    data class D1(data: Array<X>)
    
    data class X1(id): X
    data class X2(id, children: Array<Y>): X
    
    data class Y1(id): Y
    data class Y2(id, connectedItems): Y
    If there any possibility to realize deserialization for this case (according
    type
    field)?
    s

    sandwwraith

    3 years ago
    Not really for now, such format is not supported yet
    turansky

    turansky

    3 years ago
    Is there any plans to support such format?
    Is there any possibility to realize such logic via custom serializers/deserializers?
    s

    sandwwraith

    3 years ago
    Yes, there are such plans, but no ETA for it yet. I think it is possible, using intermediate representation via JSON tree: https://github.com/Kotlin/kotlinx.serialization/blob/master/runtime/jvm/src/test/kotlin/kotlinx/serialization/formats/json/JsonTreeAndMapperTest.kt#L35
    turansky

    turansky

    3 years ago
    It works if such technic is applied once. But if I use it twice (for object & for properties of this object) - it doesn’t work. Example - https://github.com/turansky/kotlinx-serialization-test Any suggestions?
    s

    sandwwraith

    3 years ago
    This is probably a problem which https://github.com/Kotlin/kotlinx.serialization/pull/254 is trying to solve
    turansky

    turansky

    3 years ago
    Do you have a plan to solve this problem in next release?
    s

    sandwwraith

    3 years ago
    yes
    turansky

    turansky

    3 years ago
    Is there any aproximate date?
    s

    sandwwraith

    3 years ago
    I think it would be around 1.3.20 Possibly eap library releases will follow Kotlin eap's
    turansky

    turansky

    3 years ago
    Coming soon?
    Is custom deserializer best solution for
    1.3.20
    +
    0.10.0
    ?
    s

    sandwwraith

    3 years ago
    Yes
    turansky

    turansky

    3 years ago
    Will
    by type
    deserialization (like in Jackson) be available later?
    s

    sandwwraith

    3 years ago
    Yes, we have it in the roadmap
    turansky

    turansky

    3 years ago
    Is there any example of custom
    by type
    deserialization?
    My example doesn't work as expected
    Any ideas?
    s

    sandwwraith

    3 years ago
    turansky

    turansky

    3 years ago
    Nonstrict mode required 🙂
    Deserialization works