在Spring数据中,可以通过POST/parent/{parentId}/nested将嵌套的@OneToMany对象添加到父级吗?

Mer*_*eVV 2 rest one-to-many spring-data-rest spring-web

我有父对象和嵌套对象.我可以获得嵌套的列表,GET /parent/{parentId}/nested但是我无法POST/PUT成功.在POST结果上,我得到HTTP 204,父亲有空的嵌套对象列表.

在日志中,我看到Hibernate不会在DB中插入任何内容.在调试期间,我看到用于deserealization的Jackson Object Mapper获得" org.springframework.hateoas.Resources<java.lang.Object>"作为JavaType.

这是我的POST的真实例子: curl 'http://localhost:8000/api/users/402880e554b8f7960154b8f7adbc0000/orders/' -i -X POST -H 'Authorization: Basic OLOLO==' -H 'Accept: application/json' -H 'deviceCurrencyCode: USD' -H 'Content-Type: application/json; charset=UTF-8' -d '{"orderPrice": 0,"tax": 0,"shippingCost": 0,"credits": 0,"addresses": [{"firstName": "Figli","lastName": "Migli","zipCode": "5555","city": "Riga","country": "Tlmltr","phone": "7777","address": "Adddr"}],"status": "status"}'

我知道这是可能的POST /nested '{"parent":"/link/to/parent"}'.但是,如果它是通过父级GET嵌套对象的方式,为什么我不能这样POST/PUT/PATCH它们?我查了一下,是RESTfull,似乎是.

Mat*_*nkt 5

spring数据休息文档中有一个"关联资源"部分,它告诉您该资源的可能性.创造一个新的孩子并将其联系起来是不可能的.

我不知道为什么会这样.

获得此行为的唯一方法(我知道)是实现为您执行此操作的自定义控制器.(确保不要@RequestMapping在自定义控制器上的类级别上使用注释,以避免覆盖比您想要的更多的弹簧数据休息功能)