While serving objects we use toResource method to transform them into resources and on the way back (posting a resource representation from client to server) how can I transform the representation back to the domain object?
I want to construct Book(@Entity) class from BookResource(extends ResourceSupport) class.
@RequestMapping(path="/", method = RequestMethod.POST, produces="application/vnd.company.app.book-v1+hal+json")
public ResponseEntity<?> addBook(@RequestBody BookResource bookResource) {
//What to do here?
}
Your BookResource should extend Resource rather than ResourceSupport.
public class BookResource extends Resource<Book> {
public BookResource(Book content, Link... links) {
super(content, links);
}
}
That way, you get the getContent() method for free, which "Returns the underlying entity."
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.