这是从 GET 请求http://domain/entry/{id}
中检索到的有效Entry对象:
{
"id": 1,
"description": "ML Books",
"dueDate": "2017-06-10",
"paymentDate": "2017-06-10",
"note": "Distribution de lucros",
"value": 6500,
"type": "INCOME",
"category": {
"id": 2,
"name": "Food"
},
"person": {
"id": 3,
"name": "User",
"active": true,
"address": {
// properties suppressed for better reading
}
}
}
在POST请求中,我想保存前面的对象 Category 和 Person ,只是发送相应的ID,如下所示:
{
"description": "NEW ENTRY",
"dueDate": "2019-06-22",
"paymentDate": "2019-06-22",
"note": "Coloured pens",
"value": 10,
"type": "INCOME",
"categoryId": 5,
"personId": 5
}
要保存对象而没有Spring表示人员和类别对象是null
,我在模型中向它们添加了@JsonIgnore
,并遵循了this线程。
部分起作用:
现在,当使用相同的 GET 请求http://domain/entry/{id}
检索条目时:
{
"id": 23,
"description": "Pens",
"dueDate": "2019-06-22",
"paymentDate": "2019-06-22",
"note": "Coloured pens",
"value": 10,
"type": "INCOME",
"categoryId": null, // It supposed to bring the entire object
"personId": null // It supposed to bring the entire object
}
PS :categoryId和personId被标记为@Transient
,这就是为什么它们为空的原因。
因此,正如标题所示,我只想在POST请求(保存它们)中而不是在GET请求(检索它们)中忽略属性Category和Person。
任何帮助都将受到欢迎。 预先感谢