Announcement Announcement Module
Collapse
No announcement yet.
Capturing org.codehaus.jackson.map.JsonMappingException in Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Capturing org.codehaus.jackson.map.JsonMappingException in Spring

    Hi Every One,

    I am using Spring MVC to Build rest webservices.

    1. I am using spring provided json converter for Json to Java Object Conversion

    <bean
    class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping" />
    <bean
    class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
    <list>
    <ref bean="jsonConverter" />

    </list>
    </property>
    </bean>

    <bean id="jsonConverter"
    class="org.springframework.http.converter.json.Map pingJacksonHttpMessageConverter">
    <property name="supportedMediaTypes" value="application/json" />
    </bean>

    2) My Controller would Look Like below.

    @RequestMapping(method = RequestMethod.POST, value = "/addAttendee", headers = "Accept=application/xml, application/json;")
    public @ResponseBody
    AddAttendeeVO addAttendee(@RequestBody AddAttendeeVO requestVO) {
    return new AddAttendeeVO();
    }

    3) AddAttendeeVO Object


    Public class AddAttendeeVO {

    private String firstName;
    private String lastName;

    }

    4) Now if i try to access this rest method with the following json

    {
    "firstName": "test",
    "lastName" : false

    }

    I am getting the below error. (Internal Service Exception 500).

    The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.codehaus.jackson.map.JsonMappingException : Can not deserialize instance of java.lang.String out of VALUE_FALSE token
    at [Source: org.apache.catalina.connector.CoyoteInputStream@40 54ac42; line: 1, column: 19]


    Now my question is , whether i can catch this exception in Controller, if consumer sends some invalid json object / Structure and send Gracefull error message to the end user.

    Thanks and Regards,
    Pradeep Alabe
Working...
X