Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse nested relationships #118

Open
jutikornpomelo opened this issue Sep 27, 2022 · 1 comment
Open

Unable to parse nested relationships #118

jutikornpomelo opened this issue Sep 27, 2022 · 1 comment
Labels

Comments

@jutikornpomelo
Copy link

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
Copy link
Owner

kamikat commented Oct 17, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants