【发布时间】:2021-02-15 21:19:57
【问题描述】:
我正在使用一个以 json api 格式提供响应的 restful web 服务。有一个具有 id 和类型参数的关系属性。根据 id 引用,它会在包含的属性中显示值。 id 是在作为最终输出处理的两个请求之后创建的。直到那时我将我的数据作为一个对象保存在数据库中。现在,当我使用 rest webservice 从数据库中获取数据时,输出显示除了包含的所有属性。我相信这是因为它无法找到参考,所以没有显示。但在数据库中,所有值都完美呈现。我不确定 json api 是否支持关系属性的多个 id。 例子: 请求正文:
{
"data": {
"type": "orders",
"attributes": {
"name": "new order",
"updateDate": "",
"register":"yes",
"items":[
{
"description": "newly added item",
"type": "new item",
"amount": [
{
"deliveryfee": "123",
"mrp": "456"
}
]
}
]
}
}
}
预期响应正文:
{
"data": {
"type": "orders",
"id": "1",
"attributes": {
"name": "new order",
"updateDate": "",
},
"relationships": {
"items": {
"data": [
{
"type": "items",
"id": null
}
]
}
}
},
"included": [
{
"type": "items",
"id": null,
"attributes": {
"type": "new item",
"description": "newly added item",
"amount": [
{
"deliveryfee": "123",
"mrp": "456"
}
]
}
}
]
}
实际响应正文:
{
"data": {
"type": "orders",
"id": "1",
"attributes": {
"name": "new order",
"updateDate": "",
},
"relationships": {
"items": {
"data": [
{
"type": "items",
"id": null
}
]
}
}
}
}
【问题讨论】:
标签: java rest web-services json-api