stantanasi / retrofit-jsonapi-converter

Retrofit JsonApi Converter is an Android library for converting JSON:API response to model and model to JSON:API format
https://jitpack.io/#stantanasi/retrofit-jsonapi-converter
Apache License 2.0
3 stars 0 forks source link

Parsing Failed for media object #1

Open nidhinek opened 2 weeks ago

nidhinek commented 2 weeks ago

In Api response if media object included as both attribute and relationship , the parsing failing with unknown error JsonApiType

sample.txt It works if I remove media from include

stantanasi commented 1 week ago

On the JSON:API specification, it says:

Fields for a resource object MUST share a common namespace with each other and with type and id. In other words, a resource can not have an attribute and relationship with the same name, nor can it have an attribute or relationship named type or id.

So you shouldn't have the same name in attributes and in relationships.


With my current code, you could fix your problem by adding the annotations @JsonApiAttribute or @JsonApiRelationship to your property media, like this:

@JsonApiType("menus")
data class Menu(
    // ......
    @JsonApiAttribute("media") val media: /* Your type */,
)