Spring HATEROAS resourcesupport & # 8594; domain object

When servicing objects, we use the toResource method to convert them to resources and on the way back (placing a resource view from the client to the server), how can I convert the view back to a domain object?

I want to build the Book class (@Entity) from the BookResource class (extends the 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?
    }
+4
source share
1 answer

Your BookResource should extend Resource , not ResourceSupport.

public class BookResource extends Resource<Book> {

    public BookResource(Book content, Link... links) {
        super(content, links);
    }

}

Thus, you get a free getContent () method that "returns the base object".

0

Source: https://habr.com/ru/post/1673898/


All Articles