moshi-jsonapi
moshi-jsonapi copied to clipboard
Unable to parse nested relationships
My JSON response has 3 nested relationships
in it which looks like this:
lib can parse the blue
and red
layers but when it comes to the green
layer. It cant be parsed and only return null
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": {}
}
]
}
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.