1

I'm trying to implement an endpoint that takes a serialized object from request parameter and deserializes it into a POJO. Is there an easy way how to do this with Spring?

The example of a query: http://localhost/routes/departures?trip=%7B%22stopId%22:%22U321Z102%22,%22routeId%22:%22L991D1%22,%22headSign%22:%22Nemocnice+Motol%22%7D which should translate into this:

trip: {"stopId":"U321Z102","routeId":"L991D1","headSign":"Nemocnice Motol"}

Also, those parameter values may contain spaces and special characters (ěščř...). Will Spring handle this? Alternatively I could send those parameters separately and not serialized, but I'm worried this would be an issue.

fugasjunior
  • 461
  • 1
  • 6
  • 22

1 Answers1

0

You need to send the user by using post request (send a userDTO that has the same type and attributes names than the one in the back end )

your rest controller is going to look like this

    @PostMapping("/users")
    @PreAuthorize("hasRole(\"" + AuthoritiesConstants.ADMIN + "\")")
    public ResponseEntity<User> createUser(@Valid @RequestBody UserDTO userDTO)      throws URISyntaxException {
    log.debug("REST request to save User : {}", userDTO);
MC Ninjava
  • 214
  • 2
  • 7
  • 1
    Thanks for the answer. In my case, POST request would go against conventions, as the endpoint is used only for retrieving data based on the parameters in the serialized object. I decided to switch to sending the query in plain params, encoding to URL and decoding using `java.net.URLDecoder`. However I'm still interested in finding whether there's a way to deserialize the way I originally planned to. – fugasjunior May 21 '19 at 15:46