-
Jul 31st, 2012, 04:30 PM
#1
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
-
Aug 1st, 2012, 12:27 PM
#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
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
-
Forum Rules