I have a RESTful web service developed using Spring MVC and without any configuration I can return objects from my @ResponseBody
annotated controller methods that get serialized to JSON. This works as soon as the Accept header in the request is not set or is application/json
.
As I'm getting inspired by the GitHub API specification, I wanted to implement custom mime type for my API as GitHub does, for example: application/vnd.myservice+json
. But then I need to tell Spring MVC that my controllers can provide this mime type and that it should be serialized by Json (i.e org.springframework.web.servlet.view.json.MappingJacksonJsonView class).
Any idea how to do it?
You can probably do exactly what is being done with
org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
. Since it is not a final class, you can derive your converter from this one this way:then register your converter this way:
It should just work with these changes