I have some controller method like:
@RequestMapping(value = "/person", method = RequestMethod.POST)
public ResponseEntity<?> create(@RequestBody Person person) {
personRepository.save(person);
return new ResponseEntity<>(HttpStatus.OK);
}
The person payload is (the link points to the uri of the department):
{
"name": "Barack Obama",
"department": "http://localhost:8080/department/1"
}
I have a PersonResource
public class PersonResource {
String name;
}
And a ResourceAssembler
public class PersonResourceAssembler extends ResourceAssemblerSupport<PersonResource, Person> {
public PersonResourceAssembler() {
super(PersonController.class, PersonResource.class);
}
@Override
public PersonResource toResource(Person person) {
PersonResource res = new PersonResource();
res.setName(person.getName());
res.add(linkTo(methodOn(DepartmentController.class).getOne(person.getDepartment().getId())).withRel("department");
}
}
DepartmentController
@RestController
@RequestMapping("/department")
public class DepartmentController {
@RequestMapping("/{id}")
public ResponseEntity<DepartmentResource> getOne(@PathVariable("id") Long id) {
Department dep = departmentRepository.findOne(id);
DepartmentResource res = departmentResourceAssembler.toResource(res);
return new ResponseEntity<>(res, HttpStatus.OK);
}
}
This would result in a json like:
{
"name": "Barack Obama",
"_links": {
"department": {
"href": "http://localhost:8080/department/1"
}
}
}
Now to the problem: When I send the create-Request with the payload, Jackson or Spring Rest/HATEOAS is not able do handle the Links during deserialization. What do I need to configure/implement to make this working?
Thanks!