у меня есть какой-то метод контроллера, как:Spring Hateoas Deserialize Ссылки в Payload для реальных лиц
@RequestMapping(value = "/person", method = RequestMethod.POST)
public ResponseEntity<?> create(@RequestBody Person person) {
personRepository.save(person);
return new ResponseEntity<>(HttpStatus.OK);
}
Человек полезной нагрузки (ссылка указывает на Ури отдела):
{
"name": "Barack Obama",
"department": "http://localhost:8080/department/1"
}
I есть PersonResource
public class PersonResource {
String name;
}
И в 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);
}
}
Это приведет в JSON как:
{
"name": "Barack Obama",
"_links": {
"department": {
"href": "http://localhost:8080/department/1"
}
}
}
Теперь проблема: Когда я посылаю создать-запрос с полезной нагрузкой, Джексон или Spring Rest/HATEOAS не может обрабатывать ссылки во время десериализации. Что мне нужно для настройки/внедрения, чтобы это работало?
Спасибо!
Вы несете ответственность за это сам. Вы можете взглянуть на Spring Data REST. – zeroflagL