JSON ``` { "data": [ { "id": "x1_1", ...
# serialization
t
JSON
Copy code
{
  "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
Copy code
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
Not really for now, such format is not supported yet
t
Is there any plans to support such format?
Is there any possibility to realize such logic via custom serializers/deserializers?
s
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
This is probably a problem which https://github.com/Kotlin/kotlinx.serialization/pull/254 is trying to solve
t
Do you have a plan to solve this problem in next release?
s
yes
t
Is there any aproximate date?
s
I think it would be around 1.3.20 Possibly eap library releases will follow Kotlin eap's
t
Coming soon?
Is custom deserializer best solution for
1.3.20
+
0.10.0
?
s
Yes
t
Will
by type
deserialization (like in Jackson) be available later?
s
Yes, we have it in the roadmap
t
Is there any example of custom
by type
deserialization?
My example doesn't work as expected
Any ideas?
s
t
Nonstrict mode required 🙂
Deserialization works