1

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?

Leon
  • 2,926
  • 1
  • 25
  • 34
  • Can you provide particular example of json for Parent entity with collection of items? Are you sure collection contains more than 10 elements? – Kostiantyn Aug 23 '18 at 14:12
  • Yes absolutely sure – M. Miatlitski Aug 23 '18 at 14:22
  • @N.Metlitski, your first item should be referenced as "path":"/collection/0/property", second as "path":"/collection/1/property", and 10th as "path":"/collection/9/property". There is no 11th element which can be referenced by "path":"/collection/10/property", and that's what your exception is about – Kostiantyn Aug 23 '18 at 17:18
  • I won't provide any examples - the problem is described clear enough. And there is a correct answer below. – M. Miatlitski Aug 24 '18 at 13:13

1 Answers1

0

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)

Eugene Maysyuk
  • 2,977
  • 25
  • 24