I followed this example, which allows to post a unique Person
object. I want a REST service where I can post a collection of Person
at once, e.g. a
Based on user1685095 answer, You can make custom Controller PersonRestController
and expose post collection of Person
as it seem not exposed yet by Spring-date-rest
@RepositoryRestController
@RequestMapping(value = "/persons")
public class PersonRestController {
private final PersonRepository repo;
@Autowired
public AppointmentRestController(PersonRepository repo) {
this.repo = repo;
}
@RequestMapping(method = RequestMethod.POST, value = "/batch", consumes = "application/json", produces = "application/json")
public @ResponseBody ResponseEntity> savePersonList(@RequestBody Resource> personWrapper,
PersistentEntityResourceAssembler assembler) {
Resources resources = new Resources(repo.save(personWrapper.getContent()));
//TODO add extra links `assembler`
return ResponseEntity.ok(resources);
}
}
PersonWrapper to fix:
Can not deserialize instance of org.springframework.hateoas.Resources out of START_ARRAY token\n at [Source: java.io.PushbackInputStream@3298b722; line: 1, column: 1]
Update
public class PersonWrapper{
private List content;
public List getContent(){
return content;
}
public void setContent(List content){
this.content = content;
}
}
public class Person{
private String name;
private String email;
// Other fields
// GETTER & SETTER
}