简体   繁体   中英

Spring Data Rest json-patch+json on collection item with index greater than 9

The entity Parent has a collection of Item objects.

Whenever I try to run a json-patch+json request that contains an operation against a collection item with an index greater than 9 Spring throws the following exception:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property 10 found for type Item! Traversed path: Parent.collection.

the URL is "/Parent/1" the request body:

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

Exactly the same request with an index less than 10 works just fine:

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

Is it a spring data rest bug?

There was an issue in Spring Data Rest project that has recently been fixed (on the 8th of August 2018) in the following releases:

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

If you use Spring Boot 2.1.x you can update your spring-data-rest-webmvc artifact version. The easiest way to do so is by setting the spring-data-releasetrain.version property to Lovelace-RC2 in your pom:

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

If you use Spring Boot 2.0.x:

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

If you use Spring Boot 1.5.x:

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

As an alternative, you can update the Spring Boot version itself to the versions that already use corresponding Spring Data Rest releases:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM