【问题标题】:Spring Data Rest json-patch+json on collection item with index greater than 9索引大于 9 的集合项上的 Spring Data Rest json-patch+json
【发布时间】:2018-08-23 13:58:53
【问题描述】:

实体 Parent 有一个 Item 对象的集合。

每当我尝试运行包含针对索引大于 9 的集合项的操作的 json-patch+json 请求时,Spring 都会引发以下异常:

原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型项目的属性 10!遍历路径:Parent.collection。

网址是"/Parent/1" 请求正文:

[
    {
      "op":"replace",
      "path":"/collection/10/property",
      "value":"100"
    }
]

索引小于 10 的完全相同的请求可以正常工作:

[
    {
      "op":"replace",
      "path":"/collection/9/property",
      "value":"100"
    }
]

是spring data rest的bug吗?

【问题讨论】:

  • 您能否提供带有项目集合的父实体的特定 json 示例?您确定集合包含超过 10 个元素吗?
  • 是的,绝对确定
  • @N.Metlitski,您的第一项应引用为“路径”:“/collection/0/property”,第二项应引用为“路径”:“/collection/1/property”,第 10 项作为“路径”:“/collection/9/property”。没有第 11 个元素可以被“path”引用:“/collection/10/property”,这就是你的例外
  • 我不会提供任何示例 - 问题描述得足够清楚。并且下面有一个正确答案。

标签: java spring-data-rest json-patch


【解决方案1】:

There was an issue 在 Spring Data Rest 项目中,has recently been fixed(2018 年 8 月 8 日)在以下版本中:

org.springframework.data:spring-data-rest-webmvc:jar:3.1.0.RC2 org.springframework.data:spring-data-rest-webmvc:jar:2.6.15.RELEASE org.springframework.data:spring-data-rest-webmvc:jar:3.0.10.RELEASE

如果您使用 Spring Boot 2.1.x,您可以更新您的 spring-data-rest-webmvc 工件版本。最简单的方法是在 pom 中将 spring-data-releasetrain.version 属性设置为 Lovelace-RC2:

<spring-data-releasetrain.version>Lovelace-RC2</spring-data-releasetrain.version>

如果你使用 Spring Boot 2.0.x:

<spring-data-releasetrain.version>Kay-SR10</spring-data-releasetrain.version>

如果你使用 Spring Boot 1.5.x:

<spring-data-releasetrain.version>Ingalls-SR15</spring-data-releasetrain.version>

作为替代方案,您可以将 Spring Boot 版本本身更新为已使用相应 Spring Data Rest 版本的版本:

org.springframework.boot:spring-boot-starter-parent:2.1.0.M2 (Lovelace-RC2)

org.springframework.boot:spring-boot-starter-parent:2.0.5.RELEASE (Kay-SR10)

org.springframework.boot:spring-boot-starter-parent:1.5.16.RELEASE (Ingalls-SR15)

【讨论】:

    猜你喜欢
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 2015-05-04
    • 2017-03-14
    • 2014-11-14
    • 1970-01-01
    相关资源
    最近更新 更多