infinum/kotlin-jsonapix

Failed to parse "link" inside "included" property

adhityasp opened this issue · 1 comments

Background

I want to parse JSON that has "link" inside "included" array. this is the example:

{
  "data": [
    {
      "type": "article",
      "id": "1",
      "attributes": {
        "title": "sample-title",
      },
      "relationships": {
        "author": {
          "data": {
            "type": "people",
            "id": "9"
          }
        }
      },
      "links": {
        "self": "http://example.com/articles/1"
      }
    }
  ],
  "included": [
    {
      "type": "people",
      "id": "9",
      "attributes": {
        "name": "Dan",
        "lastName": "Gebhardt",
        "twitter": "dgeb"
      },
      "links": { when this links is removed, the parsing works just fine
        "self": "http://example.com/people/9",
        "next": "http://example.com/articles?page[offset]=2"
      }
    }
  ]
}

When i parse that json string, i encountered this error

Polymorphic serializer was not found for missing class discriminator ('null')
JSON input: {"self":"http://example.com/people/9","next":"http://example.com/articles?page[offset]=2"}
kotlinx.serialization.json.internal.JsonDecodingException: Polymorphic serializer was not found for missing class discriminator ('null')
JSON input: {"self":"http://example.com/people/9","next":"http://example.com/articles?page[offset]=2"}
	at app//kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)
	at app//kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32)
	at app//kotlinx.serialization.json.internal.PolymorphicKt.throwSerializerNotFound(Polymorphic.kt:76)

Questions:

Do you have any idea about this ? I also checking your sample project and i added the "link" inside the "included property" on "person_list.json", the error message is the same with my error.

Hi @adhityasp and thanks for your effort and feedback!
For the time being, serializing and deserializing links in the included array is not supported. This is because the feature is fairly complex, so we postponed implementing it for a future release of the library.

By the time we make a stable release, links in included blocks will be supported.