我有这个理论上遵循 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": []
}
}