Hi All,
I love using <mvc:annotation-driven /> to setup a MappingJacksonHttpMessageConverter and being able to use the @ResponseBody annotation in my controllers to indicate the return value should be serialized. Awesome.
However, this is somewhat limiting from a customization POV. I have a Jackson Mixins I would like to use in certain controller actions, but since I have no access to the underlying ObjectMapper, I have to do something like this.
This isn't ideal from a testing POV, since the return type is void. (I'm creating my own ObjectMapper and directly writing to the response.)Code:@RequestMapping(value="/datasets/{id}", method = RequestMethod.GET) public void findDatasetById(@PathVariable Integer id, Writer writer) { List<Dataset> datasets = datasetService.findDatasetById(id); ObjectMapper om = new ObjectMapper(); om.getSerializationConfig().addMixInAnnotations(Target.class, MixIn.class); String json = om.writeValueAsString(datasets); writer.write(json); }
Is there any way to get access to the ObjectMapper in the HttpMessageConverter created by <mvc:annotation-driven />? And can it be made a prototype bean? That would be so useful!
Thanks


Reply With Quote
