infinum/flutter-plugins-japx

Array relationships in included relationships are set to null if they are not present

nicobritos opened this issue · 2 comments

Array relationships (one-many) that are part of the "included" field have their items set as null when they themselves are not included in the server response. For example:

{
    {
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!",
      "body": "The shortest article. Ever.",
      "created": "2015-05-22T14:56:29.000Z",
      "updated": "2015-05-22T14:56:28.000Z"
    },
    "relationships": {
      "author": {
        "data": {"id": "42", "type": "people"}
      }
    }
  },
  "included": [
    {
      "type": "people",
      "id": "42",
      "attributes": {
        "name": "John",
        "age": 80,
        "gender": "male"
      },
      "relationships": {
        "article": {
          "data": {"id": "1", "type": "articles"}
        },
        "categories" : {
          "data" : [
            {"id": "1", "type": "categories"}
          ]
        }
      }
    }
  ]
}

Here relationships.article will be correctly parsed and shown, but categories.data will be set to a array with all its items in null (it won't even be an empty array, breaking applications on some server responses).

The expected output is:

{
  "data": {
    "type": "articles",
    "id": "1",
    "title": "JSON API paints my bikeshed!",
    "body": "The shortest article. Ever.",
    "created": "2015-05-22T14:56:29.000Z",
    "updated": "2015-05-22T14:56:28.000Z",
    "author": {
      "type": "people",
      "id": "42",
      ...
      "categories": [
        {
          "type": "categories",
          "id": "1"
        }
      ],
      "article": { ... }
    }
  }
}

The actual output is

{
  "data": {
    "type": "articles",
    "id": "1",
    "title": "JSON API paints my bikeshed!",
    "body": "The shortest article. Ever.",
    "created": "2015-05-22T14:56:29.000Z",
    "updated": "2015-05-22T14:56:28.000Z",
    "author": {
      "type": "people",
      "id": "42",
      ...
      "categories": [
        null
      ],
      "article": { ... }
    }
  }
}

This is fixed in #19

have same issue, can someone @KhaleelSH @Truba help merge and update a new version?

Sorry for the wait. 2.1.0 is out