1

Here is my Controller code:

@RequestMapping(value = "/accountholders/{cardHolderId}/cards/{cardId}", produces = "application/json; charset=utf-8", consumes = "application/json", method = RequestMethod.PUT)
@ResponseBody
public CardVO putCard(@PathVariable("cardHolderId") final String cardHolderId,
        @PathVariable("cardId") final String cardId, @Valid @RequestBody final RequestVO requestVO,
        @RequestParam final Map<String, String> allRequestParams) {
    iCardService.updateCardInfo(cardId, requestVO.getActive());
    return iCardService.getCardHolderCardInfo(cardHolderId, cardId);

}

THis is my Request Bean:-

public class RequestVO {
    @NotNull
    private Boolean active;

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

My request Body:-

{
    "active":true,
    "abc":"ignoring this"
}

The problem I am having is when i sent an extra parameter in the request Body It seems to ignore the extra value in this case "abc". The code works and give me the response What I need to throw is 400 BAD REQUEST.

Am i missing something or is their a way to tell it to throw an exception when an extra parameter is passed.

Grinish Nepal
  • 3,037
  • 3
  • 30
  • 49

1 Answers1

4

Try this:

@JsonIgnoreProperties(ignoreUnknown = false)
public class RequestVO {
    @NotNull
    private Boolean active;

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }
}
Abhishek Garg
  • 2,158
  • 1
  • 16
  • 30
  • Hint: for a global configuration, have a look at this answer: http://stackoverflow.com/a/14343479/280244 – Ralph Feb 11 '16 at 21:49
  • i tried the solution but i still get the response. i imported the com.fasterxml.jackson.annotation.JsonIgnoreProperties. still same result. – Grinish Nepal Feb 11 '16 at 22:08