在使用curl POST添加新实体期间,@ RepositoryRestResource实体字段为null

时间:2018-11-10 16:11:35

标签: java spring spring-boot spring-data-jpa spring-data

这是一个春季启动应用程序,我有两个@Entity和它们各自的@RepositoryRestResource。在数据库中,App是父级,History是子级。当我尝试将新记录添加到“历史记录”(使用POST)时,我无法弄清楚为什么versiontag在响应中为空。

这些字段在DB中也是null。调试发现请求未正确反序列化。有人见过这个问题吗?

怀疑是this修复程序的原因,无法真正确认,因为降级杰克逊版本无济于事。完整的申请是here

$ curl -d '{"app":{"appId":1,"name":"test2"},"version":"v13","tag:"tagtest1"}' -H "Content-Type: application/json" -X POST http://localhost:8080/repo/history

响应:

{
  "version" : null,
  "tag" : null,
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/repo/history/1"
    },
    "history" : {
      "href" : "http://localhost:8080/repo/history/1"
    },
    "app" : {
      "href" : "http://localhost:8080/repo/history/1/app"
    }
  }
}

1 个答案:

答案 0 :(得分:0)

我克隆了您的存储库,并且可以正常工作,但是有几件事,我不确定如何直接发送ManyToOne对象,因为这是映射它的错误。因为如果发送下面的正文,它将被映射版本和标签,但应用程序的JSON对象不是,因此您必须研究如何通过具有多对一关系的JSON对象进行传递。您需要看一下这个答案Save child objects automatically using JPA Hibernate

{
    "version":"v13",
    "tag":"tagtest1",
    "app":{
        "appId": 1, 
        "name":"test112"
    }
}