Announcement Announcement Module
Collapse
No announcement yet.
Data Binding Error Handling in Spring MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment

    Working...
    X