kamikat / moshi-jsonapi

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

Unable to parse nested relationships #118

Open jutikornpomelo opened 2 years ago

jutikornpomelo commented 2 years ago

My JSON response has 3 nested relationships in it which looks like this: image

lib can parse the blue and red layers but when it comes to the green layer. It cant be parsed and only return null

image

My data class:

@JsonApi(type = "navigation-items")
data class JsonNavigationItem(
    @field:Json(name = "id_category") val categoryId: Int? = null,
    val name: String? = null,
    @field:Json(name = "text_color") val textColor: String? = null,
    val media: JsonMedia? = null,
    @field:Json(name = "navigation-items") val navigationItems: HasMany<JsonNavigationItem>? = null,
) : Resource()

Here is my sample json:

{
    "data": [{
            "type": "navigation-items",
            "id": "3169",
            "attributes": {
                "id_category": 61,
                "name": "Accessories",
                "link_rewrite": "accessories"
            },
            "relationships": {
                "navigation-items": {
                    "data": [{
                            "type": "navigation-items",
                            "id": "73",
                            "relationships": {
                                "navigation-items": {
                                    "data": [{
                                            "type": "navigation-items",
                                            "id": "79"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "80"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "124"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "101"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "396"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "397"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "398"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "399"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "400"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "109"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "401"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "2293"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "402"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "403"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "247"
                                        },
                                        {
                                            "type": "navigation-items",
                                            "id": "404"
                                        }
                                    ]
                                }
                            }
                        },
                        {
                            "type": "navigation-items",
                            "id": "74"
                        },
                        {
                            "type": "navigation-items",
                            "id": "77"
                        },
                        {
                            "type": "navigation-items",
                            "id": "75"
                        }
                    ]
                }
            }
        },
        {
            "type": "navigation-items",
            "id": "3225",
            "attributes": {
                "id_category": 12,
                "name": "Shirts - Short Sleeve",
                "link_rewrite": "shirts-short-sleeve"
            },
            "relationships": {}
        }
    ]
}
kamikat commented 2 years ago

A resource linkage object (the data field in values of relationships field) can be a single or an array of resource identifier object. AFAIK, the use of relationships in a resource identifier object is not supported by the specification.