2

I have a controller as following:

@RequestMapping(path = "validate", method = POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = APPLICATION_JSON_UTF8_VALUE) public ResponseEntity<Object> validate(@Valid @ModelAttribute ValidationRequest request) { } 

ValidationRequest is a POJO with couple of fields.

With this setup, I expect this method to accept POST parameters passed only through body of request. However, if we make a POST request like http://localhost:8080/validate?param1=a&param2=b without any body, it still accepts it. I have marked all of fields inside ValidationRequest as mandatory.

Any suggestions? Am I missing something here?

1
  • Post your POJO ValidationRequest as well Commented Mar 1, 2016 at 7:17

2 Answers 2

1

Perhaps try @RequestBody instead of @ModelAttribute.

Sign up to request clarification or add additional context in comments.

Comments

0

you can use @PathParam.

@POST @Path("/validate/{param1}/{param2}") @Consumes({ "application/json", "text/plain" }) @Produces({ "application/json" }) public ResponseEntity<Object> validate(@Valid @ModelAttribute ValidationRequest request, @PathParam("param1") String param1, @PathParam("param2") String param2) { .................. } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.