spring data rest:带投影参数的PATCH请求

时间:2015-12-16 18:00:27

标签: projection spring-data-rest

我正在使用SDR 2.4.1

当我执行时

http -v --auth admin:admin --json PATCH http://localhost:8080/api/messages/61?projection=withAccount readTimestamp="2015-12-15T11:32:06.380+0000"

我得到以下异常:

java.lang.IllegalArgumentException: Target bean is not of type of the persistent entity!
    at org.springframework.util.Assert.isTrue(Assert.java:68) ~[spring-core-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:394) ~[spring-data-commons-1.11.1.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.support.ETag.getVersionInformation(ETag.java:191) ~[spring-data-rest-webmvc-2.4.1.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.support.ETag.from(ETag.java:76) ~[spring-data-rest-webmvc-2.4.1.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.prepareHeaders(AbstractRepositoryRestController.java:171) ~[spring-data-rest-webmvc-2.4.1.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.prepareHeaders(AbstractRepositoryRestController.java:157) ~[spring-data-rest-webmvc-2.4.1.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.RepositoryEntityController.saveAndReturn(RepositoryEntityController.java:495) ~[spring-data-rest-webmvc-2.4.1.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.RepositoryEntityController.patchItemResource(RepositoryEntityController.java:442) ~[spring-data-rest-webmvc-2.4.1.RELEASE.jar:na]

但是当我执导时:

http -v --auth admin:admin --json PATCH http://localhost:8080/api/messages/61?foo=bar readTimestamp="2015-12-15T11:32:06.380+0000"

一切都很好。

所以它似乎是导致异常的投影参数。

这是一个错误吗?

感谢你

2 个答案:

答案 0 :(得分:0)

我不认为这是一个错误 - 预测并不意味着在写请求中使用 - 它们只是一种提供不同数据视图的方法。在创建更新资源时,您将在spring数据休息中绑定到实体结构。我知道定制它的唯一方法是使用Jackson Mixins。

答案 1 :(得分:0)

嗯,我认为补丁请求应该简单地忽略投影参数,因为它也忽略了foo paarm ......不是吗? ;)