【问题标题】:JSON API relationships with moshiJSON API 与 moshi 的关系
【发布时间】:2017-05-28 23:12:08
【问题描述】:

我的响应 JSON 在理论上遵循 JSON API 规范。我正在尝试使用moshi-jsonapi library 进行解析,但我不知道如何解析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": []
  }
}

【问题讨论】:

    标签: android json json-api moshi


    【解决方案1】:

    唯一的问题是成员的名字,在将someObjects 更改为“some_objects”之后,它就像一个魅力。

    【讨论】:

      猜你喜欢
      • 2019-11-20
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      • 2016-09-18
      • 2020-07-20
      • 1970-01-01
      相关资源
      最近更新 更多