Results 1 to 2 of 2

Thread: Data Binding Error Handling in Spring MVC

  1. #1
    Join Date
    Jul 2012
    Posts
    4

    Default Data Binding Error Handling in Spring MVC

    Have a question on the data Binding in Spring MVC.

    I have a Controller which accepts a JSON request in the form of @RequestBody.. I have all the JSR 303 Validations in place and it works like a charm.

    JSON Request

    public class TestJSONRequest{

    @Size(min=10,message="{invalid.demo.size}")
    String demo;

    int code;
    }
    Controller

    @Controller
    @RequestMapping("/test")
    public class TestController {

    public void testEntry(@RequestBody TestJSONRequest jsonRequest,ModelMap map)

    Set<ConstraintViolation<TestJSONRequest>> violationList = validator.val(jsonRequest);
    ....
    ....
    TestJSONResponse response = // Do complex Logic.
    modelMap.addattribute("TestJSONResponse",response) ;
    }
    But JSR 303 valiadtions kick in once the incoming json data is binded to the Request Object.

    In case if I send "ab" in the code field of the input JSON requsest, binding would itself fail.

    How do I handle that?

    I want to catch those data binding errors and do some kind of generalized error handling in my controller.

    Could you please help me out on this?

    P.S - I am using Spring 3.0

    Thanks,
    Santhosh

  2. #2
    Join Date
    Jul 2012
    Posts
    4

    Default

    Can somebody help me out with this ? I am stuck with this for 2 days now... It would be great if somebody can provide a clear solution to this prob ?

    Thanks,
    Santhosh

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •