Created
August 5, 2015 18:02
-
-
Save jeffsheets/616bc9c2ffa6e5b48dc6 to your computer and use it in GitHub Desktop.
A MappingJackson2HttpMessageConverter that forces the response Content-Type header to be application/json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContentTypeMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter { | |
/** | |
* Always set the Content-Type response header to application/json when using the Jackson message converter | |
* | |
* Without this there appears to be a conflict with Meteor/Atmosphere servlet that causes Spring | |
* to leave the Content-Type blank in the response | |
* https://groups.google.com/forum/#!topic/atmosphere-framework/uZOrfXl3Bu8 | |
*/ | |
@Override | |
protected void writeInternal(Object object, HttpOutputMessage outputMessage) | |
throws IOException, HttpMessageNotWritableException { | |
outputMessage.getHeaders().setContentType(MediaType.APPLICATION_JSON); | |
super.writeInternal(object, outputMessage); | |
} | |
} |
@greatbody, you'll need to register it as a messageConverter, usually in a WebMvcConfigurer extension class.
sorry for the slow response, apparently github still doesn't notify for comments on gists...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where should we place this class?