Spring数据Rest补丁添加到嵌入列表
我很难使用SpringDataREST和补丁请求添加到嵌入式列表中。我使用的是MongoDB,所以这里没有JPA连接(ManyToOne等),只是一个普通的、常规的嵌入子类型列表 我的豆子是这样的:Spring数据Rest补丁添加到嵌入列表,spring,mongodb,rest,patch,spring-data-rest,Spring,Mongodb,Rest,Patch,Spring Data Rest,我很难使用SpringDataREST和补丁请求添加到嵌入式列表中。我使用的是MongoDB,所以这里没有JPA连接(ManyToOne等),只是一个普通的、常规的嵌入子类型列表 我的豆子是这样的: class Parent { String name; List<Child> children; } class Child { String name; } curl -d '{"children": [ {"name": "bob"} ] }' -H "Conten
class Parent {
String name;
List<Child> children;
}
class Child {
String name;
}
curl -d '{"children": [ {"name": "bob"} ] }' -H "Content-Type: application/json" -X PATCH http://localhost:8080/api/parent/123
其结果是,所有子元素都被请求中的新元素替换,例如
old: [ 'tom', 'sally' ]
request: [ 'bob' ]
expected result: [ 'tom', 'sally', 'bob']
actual result: [ 'bob' ]
我已经浏览了Spring代码(DomainObjectReader),它似乎无法处理我的场景,但这确实是一个非常简单的用例,有什么想法吗?我错过了什么明显的东西吗
谢谢 问题在于您试图编辑父对象,而不是关系集合
POST /api/child {...}
PATCH /api/parent/123/children
Content-Type:text/uri-list
body: ***the URI of the child***