I use the framework Spring Data Rest for my API end points and controller.
I want to take in an URI to an entity and have spring convert it automatically
For many years the way I've been doing it this way
@PostMapping(value = "/sendEmail")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Void> submit(@RequestParam String uri, String anotherThing) throws Exception {
convert(uri); //manual conversion done by me using UriToEntityConverter
}
Is there a way for spring to just do this? I've read something about using Resources but I've tried different ways none work
@PostMapping(value = "/sendEmail")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Void> submit(@RequestBody Resource<DTO> dto) throws Exception {
//exception cannot create resource
}
@Getter
@Setter
public class DTO {
String anotherThing;
Entity entity;
}
Desired JSON input
{
"entity":"https://localhost:8080/api/v1/books/226",
"anotherThing": "hi"
}