kamikat / moshi-jsonapi

JSON API v1.0 Specification in Moshi.
MIT License
156 stars 34 forks source link

JsonDataException parsing a null attribute #43

Closed antonicg closed 7 years ago

antonicg commented 7 years ago

If you are receiving from Retrofit request as response an included object with a relation that has a null attribute and you declared it as String is giving: com.squareup.moshi.JsonDataException: Expected a name but was NULL at path $.attributes.logo_url

The response:

"links": {
    "self": "someurl/params"
  },
  "data": [
    {
      "type": "some_type",
      "id": "12345",
      "attributes": {
        "attr1": 1,
        "attr2": 2,
        "attr3": 3
      },
      "relationships": {
        "some_objects": {
          "data": [
            {
              "type": "some_objects",
              "id": "1"
            },
            {
              "type": "some_objects",
              "id": "2"
            }
          ]
        }
      }
    }
  ],
  "included": [
    {
      "type": "some_objects",
      "id": "1",
      "attributes": {
        "id": "1",
        "parentId": "1"
      },
      "relationships": {
        "subobjects": {
          "data": [
            {
              "type": "subobjects",
              "id": "2"
            }
          ]
        }
    }
    {
      "type": "subobjects",
      "id": "2",
      "attributes": {
        "name":"a name",
       "logo_url":null
      }
    }
  ],
  "meta": {
    "total": 1,
    "totalCount": 1,
    "correction": []
  }
}
kamikat commented 7 years ago

It's fixed in version 3.0.5. Thanks for your help 😸