2

我有这个理论上遵循 JSON API 规范的响应 JSON。我正在尝试使用moshi-jsonapi 库进行解析,但我不知道如何解析这种some_objects关系。在SomeType班级中,我有一个成员HasMany<SomeObject> someObjects,并且该班级SomeObject以适当的方式进行了注释:

@JsonApi(type = "some_objects")
public class SomeObject extends Resource {
//....
}

但是,在进行解析之后,我将someObjects成员设为空。有谁知道为什么?

JSON就是这样一个:

  "links": {
    "self": "someurl/params"
  },
  "data": [
    {
      "type": "some_type",
      "id": "12345",
      "attributes": {
        "attr1": 1,
        "attr2": 2,
        "attr3": 3
      },
      "relationships": {
        "some_objects": {
          "data": [
            {
              "type": "some_objects",
              "id": "1"
            },
            {
              "type": "some_objects",
              "id": "2"
            }
          ]
        }
      }
    }
  ],
  "included": [
    {
      "type": "some_objects",
      "id": "1",
      "attributes": {
        "id": "1",
        "parentId": "1"
      },
      "relationships": {
        "subobjects": {
          "data": [
            {
              "type": "subobjects",
              "id": "2"
            }
          ]
        }
    }
    {
      "type": "subobjects",
      "id": "2",
      "attributes": {
        "metadata": {
            "code": "AA"
        },
        "id": "2",
        "parentId": "1"
      }
    }
  ],
  "meta": {
    "total": 1,
    "totalCount": 1,
    "correction": []
  }
}
4

1 回答 1

0

唯一的问题是成员的名称,在someObjects通过“some_objects”更改后,它就像一个魅力。

于 2017-01-16T13:32:42.563 回答