Convert form data to object (DTO)

1.7k Views Asked by At

I have this route in controller which accepts - application/x-www-form-urlencoded

@RequestMapping(value = "/browser", method = RequestMethod.POST, produces = {"application/xml"}, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseBody
public ResponseEntity<String> processServerCallback(@RequestBody final MultiValueMap<String, String> formVars) {
    System.out.println(formVars);
    return null;
}

Now I need to convert formVars to my DTO object. How can I do that?

1

There are 1 best solutions below

0
On

Say, formVars looks like this:

public class FormVars{
private String name;
private int age;
//constructors and getters and setters
}`

Then in your controller method, you need to replace @RequestBody MultiValueMap<String, String> with @RequestBody FormVars formVars