JSON-PATCH上的异常发布到Spring Data REST中的@RepositoryRestResource

Way*_*yne 6 spring-mvc json-patch

我无法让Spring Data REST接受JSON-PATCH内容体,我做错了什么?

简单域名:

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

由MondoDB回购支持:

@RepositoryRestResource
public interface DomainARepository extends MongoRepository<DomainA, String> {}
Run Code Online (Sandbox Code Playgroud)

我想要JSON-PATCH这样,如下:

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
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我得到一个例外:

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)
Run Code Online (Sandbox Code Playgroud)

....

如果我提供没有阵列支架的补丁体,我会回到204; 也没有例外,但也没有对文件进行任何更改.我可以"打补丁"的文件使用PUTPATCH{"atext":"PUTed value"}; POST/GET工作正常; 并且,Spring Data REST中的测试似乎验证了如果我可以接受内容主体,JSON-PATCH 应该可以工作.那么,在这里使用PATCH的正确方法是什么?

(使用Spring Boot 1.2.2.RELEASE启动程序为-data-mongodb,-data-rest,java 1.8)

编辑:如果我回到JPA(H2)CRUD @RepositoryRestResource repo,则会出现相同的异常.

编辑:在https://jira.spring.io/browse/DATAREST-498打开JIRA