moshi-jsonapi
moshi-jsonapi copied to clipboard
Problem with parsing empty Relationship array
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": []
}]
}
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