kamikat / moshi-jsonapi

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

Fails to deserialize hasMany relationship when empty #80

Closed Bartheleway closed 6 years ago

Bartheleway commented 6 years ago

Hi, first thanks for your work.

I'm having some trouble with a hasMany relationship which actually has no records.

I have a JSON like that :

{
  "data": [
    {
      "type": "articles",
      "id": "1",
      "attributes": {
        "title": "My Title",
      },
      "relationships": {
        "comments": {
          "data": null
        }
      }
    }
  ],
}

My model is like that

@JsonApi(type = "article")
public class Article extends UpdatableResource {
  public String title;
  public HasMany<Comment> comments;
}

I'm getting this error : com.squareup.moshi.JsonDataException: Expected BEGIN_ARRAY but was NULL at path $.data[0].relationships.comments.data

I'm using this converter for retrofit

kamikat commented 6 years ago

Released by 3.4.0 :tada: