[英]Spring Data Rest - Embedded entity not deserialized on POST
I have a spring data rest project set up with Persistence entities Employer
and Employee
.我有一个使用持久性实体
Employer
和Employee
设置的 spring 数据休息项目。 Employee
has a @ManyToOne
relationship defined to Employer
as follows: Employee
有一个@ManyToOne
关系定义给Employer
,如下所示:
@Entity
@Table(name = "EMPLOYEE")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
...
@ManyToOne
private Employer employer;
...
}
This works well when I have a unit test persisting an Employee
that has within it an Employer
object.当我有一个单元测试持久化一个
Employee
,这很有效,其中包含一个Employer
对象。 However, when I submit a POST request with a JSON body to my endpoint, I notice that the deserialized Employer
information is null...但是,当我向端点提交带有 JSON 正文的 POST 请求时,我注意到反序列化的
Employer
信息为空...
TRACE 16948 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Arguments: [org.springframework.data.rest.webmvc.RootResourceInformation@71b498f9, Resource { content: Employee [id=1, ename=John, surname=Snow, jobTitle=Crow, companyName=Wall, companyContact=Warden of North, employeeNumber=, costCentre=, employer=null], links: [] }, org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler@5e618dcb, */*]
This tells me that my Employee
JSON isn't being deserialized correctly.这告诉我我的
Employee
JSON 没有被正确反序列化。 Is there some config I need to add to get this to happen automatically, or do I need to create my own deserializer to handle this scenario?是否需要添加一些配置以使其自动发生,或者我是否需要创建自己的解串器来处理这种情况?
看到仍然没有答案:) 我做了问题中讨论的解决方法 - 我创建了一个自定义解串器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.