kamikat / moshi-jsonapi

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

Problem with parsing empty Relationship array #89

Open mkonkel opened 5 years ago

mkonkel commented 5 years ago

java.lang.RuntimeException: java.lang.Exception: com.squareup.moshi.JsonDataException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $.data[0].relationships

Retrofit call:

    @GET("someApi/someModel")
    fun getSomeModel(): Single<ArrayDocument<SomeModel>>

Model:

@JsonApi(type = "some_model")
public class SomeModel extends Resource {
    @Json(name = "foo")
    public String foo;
    @Json(name = "bar")
    public String bar;
}

Response:

{
    "data": [{
        "type": "some_model",
        "id": 1,
        "attributes": {
            "foo": "text text",
            "bar": "text text"
        },
        "relationships": [],
        "links": []
    }]
}
dandehavilland commented 4 years ago

I know this is an old one, but just in case anyone else comes across this problem:

relationships should be an object, not an array: https://jsonapi.org/format/#document-resource-object-relationships