I have a spring data rest project set up with Persistence entities Employer
and Employee
. Employee
has a @ManyToOne
relationship defined to Employer
as follows:
@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. However, when I submit a POST request with a JSON body to my endpoint, I notice that the deserialized Employer
information is null...
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. 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?
看到仍然没有答案:) 我做了问题中讨论的解决方法 - 我创建了一个自定义解串器。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.