jasminb / jsonapi-converter

JSONAPI-Converter is a Java/Android library that provides support for working with JSONAPI spec
Apache License 2.0
272 stars 81 forks source link

Object with relations itself #245

Closed sokolking closed 3 years ago

sokolking commented 3 years ago

How to parse object, which have in relations same object?

like that

   "type": "filters",
            "id": "6",
            "attributes": {
                "name": "",
                "url": "",
                "country": "",
                "state": "",
                "selectable":,
                "type": null,
                "typeId": null
            },
            "relationships": {
                "children": {
                    "data": [
                        {
                            "type": "filters",
                            "id": "9"
                        },
                        {
                            "type": "filters",
                            "id": "10"
                        },
                        {
                            "type": "filters",
                            "id": "11"
                        },

I tried that code:

@Type("filters")
@JsonIgnoreProperties(ignoreUnknown = true)
class NewFilter : BaseResource() {
    val name: String? = null
    val url: String? = null
    val country: String? = null
    val state: String? = null
    val selectable: Boolean? = null
    val type: String? = null
    val typeId: Int? = null

    @Relationship("children")
    val childrens: List<NewFilter>? = null
}

But got that error: com.github.jasminb.jsonapi.exceptions.InvalidJsonApiResourceException: Primary data must be either a single resource object, a single resource identifier object, or null

sokolking commented 3 years ago

Sorry. My bad. Used single object instead of list