I am configuring my Spring project to add JSON Prefix )]}',\n
to overcome common vulnerability. I tried configuring per this link, its causing exception while starting up the server. Please help me out resolving this.
@Configuration
@EnableWebMvc
public Class WebAppConfig extends WebMvcConfigurationSupport
{
public void addPrefixJSON()
{
List<HttpMessageConverter<?>> converters = super.getMessageConverters();
MappingJackson2HttpMessageConverter convert = new MappingJackson2HttpMessageConverter();
convert.setPrefixJson(true);
converters.add(convert);
}
}
and I am getting the follwing exception,
08:01:23,435 ERROR [org.springframework.web.context.ContextLoader]
(ServerService Thread Pool -- 68) Context initialization failed:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource
[org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is
org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerMapping()] threw exception; nested exception is
java.lang.ClassCastException: org.springframework.web.accept.ContentNegotiationManagerFactoryBean$$EnhancerByCGLIB$$6af53d42 cannot be cast to
org.springframework.web.accept.ContentNegotiationManager
I have included <mvc:annotation-driven />
in my spring-servlet.xml Do we have any other manual methods to add the prefix in older version's of Jackson, say Jackson 1.6?
Update:
The problem is fixed with Jackson 2.0 and I'm able to view the prefix in the browser, however I am not able to see the output from angular end.
My configuration is like:
<mvc:annotation-driven content-negotiation-manager="contentManager">
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="jsonPrefix" value=")]}',\n" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
and the JSON output is
)]}',\n"{\"userName\":\"ABC\",\"emailId\":\"ABC@gmail.com\"}"
I'm perplexed with this output, besides Angular is not recognizing the output and not able to read the values from this object. Any help would be greatful. Thanks in advance.