Spring web application, try to send response as json throwing error 500 error
json, spring, spring-mvc, web-applications
Solution
It looks like you need to use at least Jackson version 1.9.2 or above. In the source for Jackson 1.9.0 and 1.9.1, the method definition for org.codehaus.jackson.map.SerializationConfig.isEnabled() has been removed. This is why you are receiving the NoSuchMethodError exception.
Then in the source code for Jackson 1.9.2 you see the following:
/*
/**********************************************************
/* MapperConfig overrides for 1.8 backwards compatibility
/**********************************************************
*/
/* NOTE: these are overloads we MUST have, but that were missing
* from 1.9.0 and 1.9.1. Type erasure can bite in the ass...
*<p>
* NOTE: will remove either these variants, or base class one, in 2.0.
*/
/**
* Alias for {@link MapperConfig#isEnabled(org.codehaus.jackson.map.MapperConfig.ConfigFeature)}.
*
* @since 1.0 However, note that version 1.9.0 and 1.9.1 accidentally missed
* this overloaded variant
*/
public boolean isEnabled(SerializationConfig.Feature f) {
return (_featureFlags & f.getMask()) != 0;
}
So in short, don't use Jackson version 1.9.0 or 1.9.1 with Spring MVC as the Jackson developers removed something that is actually required.
Problem
I am developing a web application in Spring framework. When the requests are getting served as ModelAndView respose type. It is working good but when i try to serve response as json it is throwing an error as exception ``` org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.codehaus.jackson.map.SerializationConfig.isEnabled(Lorg/codehaus/jackson/map/SerializationConfig$Feature;)Z org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259) ``` root cause ``` java.lang.NoSuchMethodError: org.codehaus.jackson.map.SerializationConfig.isEnabled(Lorg/codehaus/jackson/map/SerializationConfig$Feature;)Z org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:193) ``` Method in Controller ``` @RequestMapping(value="/getFBFriendsList",method=RequestMethod.GET)<br/> public @ResponseBody List<String> getStatesList(HttpServletRequest req){<br/> List<String> statesList = null; try{<br/> statesList = new ArrayList<String>();<br/> //..here i am getting states from datebase and adding to list<br/> }<br/> catch(Exception e){}<br/> return statesList; } ``` Configurations in dispatcher Servlet ``` <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" > <property name="supportedMediaTypes" value="application/json" /> </bean> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="jsonHttpMessageConverter" /> </list> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass"> <value> org.springframework.web.servlet.view.tiles2.TilesView </value> </property> </bean> ``` And i am using jackson jars - jackson-core-asl-1.9.0.jar - jackson-mapper-asl-1.9.0.jar - json-lib-0.9.jar and Spring version is 3.2.4