I centralized exception handling for my leisure service in a neat ControllerAdvice.
I return regular wrapping objects, in the hope that my cool display is the jackson converter, which will convert it to JSON for the end client.
Now here's the thing. If I do not set the accept-header to "Application / JSON", I do not get the converted JSON, instead I get the default HTML in my tests, which are apparently generated by Jetty. I have to admit that I'm not sure why, but I assume some default is Spring by default, which takes effect.
It made me think. Clients who call my vacation url should know that I am returning JSON, so I would like my service to always return json independently.
Is there a way to configure ReqeustMappingHandlerAdapter to always create JSON?
my current configuration:
<beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<beans:property name="messageConverters">
<beans:list>
<beans:ref bean="jsonConverter"/>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
</beans:bean>
source
share