moshi-jsonapi icon indicating copy to clipboard operation
moshi-jsonapi copied to clipboard

Problem with parsing empty Relationship array

Open mkonkel opened this issue 6 years ago • 1 comments

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": []
	}]
}

mkonkel avatar Dec 11 '18 13:12 mkonkel

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

dandehavilland avatar Jul 27 '20 05:07 dandehavilland