【问题标题】:spring data rest: PATCH request with projection paramspring data rest:带有投影参数的 PATCH 请求
【发布时间】:2016-03-23 00:01:17
【问题描述】:

我正在使用 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"

一切都很好。

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

这是一个错误吗?

谢谢

【问题讨论】:

  • 我已经为这个问题开了一个ticket(不久前)。

标签: projection spring-data-rest


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2016-01-20
      • 1970-01-01
      • 2017-07-27
      • 2015-03-07
      • 1970-01-01
      • 2018-04-18
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多