7

I can't get Spring Data REST to accept a JSON-PATCH content body, what am I doing wrong?

Simple domain:

@Document
public class DomainA {
    @Id private String id;
    private String atext;
    public String getAtext(){ return atext;}
    public void setAtext(String str){ atext = str;}
}

Backed by a MondoDB repo:

@RepositoryRestResource
public interface DomainARepository extends MongoRepository<DomainA, String> {}

I want to JSON-PATCH this,like so:

curl -X PATCH -H "Authorization: Basic dXNlcjpQVw=="
-H "Content-Type: application/json-patch+json"
-H "Cache-Control: no-cache"
-d '[{"op":"replace", "path":"/atext", "value":"JSON-PATCHed text"}]' 
http://localhost:8080/domainAs/550e169209a5cc0df82c95d4

But when I do I get an exception:

org.springframework.http.converter.HttpMessageNotReadableException:
Could not read an object of type class patchex.DomainA from the request!;
nested exception is
org.springframework.http.converter.HttpMessageNotReadableException:
Could not read payload!; nested exception is java.lang.ClassCastException:
com.fasterxml.jackson.databind.node.ArrayNode cannot be cast to
com.fasterxml.jackson.databind.node.ObjectNode at
    org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.readPatch(PersistentEntityResourceHandlerMethodArgumentResolver.java:183)

....

If I supply the patch body without the array brackets, I get back a 204; no exception but no change to the document, either. I can "patch" the document using PUT or PATCH of {"atext":"PUTed value"}; POSTs/GETs work fine; and, the tests in Spring Data REST seem to verify that JSON-PATCH should work if I can get the content body accepted. So, what's the right way to using PATCH here?

(Using Spring Boot 1.2.2.RELEASE starters for -data-mongodb, -data-rest, java 1.8)

EDIT: Same exception if I back with a JPA (H2) CRUD @RepositoryRestResource repo.

EDIT: Opened JIRA at https://jira.spring.io/browse/DATAREST-498

Wayne
  • 1,075
  • 1
  • 10
  • 21

0 Answers0