[ https://issues.apache.org/jira/browse/CAMEL-11970?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen resolved CAMEL-11970. --------------------------------- Resolution: Fixed Assignee: Claus Ibsen Thanks for the patch. I ammended it a bit and built an unit test. > JacksonDataFormat does not pickup custom ObjectMapper from Registry > ------------------------------------------------------------------- > > Key: CAMEL-11970 > URL: https://issues.apache.org/jira/browse/CAMEL-11970 > Project: Camel > Issue Type: Improvement > Components: camel-jackson > Affects Versions: 2.19.2, 2.19.3, 2.20.0 > Reporter: Tim Lark > Assignee: Claus Ibsen > Priority: Major > Fix For: 2.21.0 > > > When a custom ObjectMapper is properly configured as a Spring bean and exists > in the Registry, it is ignored when the {{JacksonDataFormat.doStart}} method > is invoked. > The beginning of this method does a null check on {{objectMapper}} and simply > creates one via {{new ObjectMapper()}} if null. > I've prototyped a more robust solution below, which does pickup our custom > ObjectMapper bean: > +Before:+ > {code:java} > @Override > protected void doStart() throws Exception { > if (objectMapper == null) { > objectMapper = new ObjectMapper(); > } > ... > {code} > +After:+ > {code:java} > @Override > protected void doStart() throws Exception { > if (objectMapper == null) { > CamelContext context = getCamelContext(); > if (context == null) { > LOG.error("doStart: No camelContext defined"); > } > else { > Map<String, ObjectMapper> mappersByName = context > .getRegistry() > .findByTypeWithName(ObjectMapper.class); > LOG.debug("doStart: Found objectMappers={}", mappersByName); > if (mappersByName.size() >= 1) { > Map.Entry<String, ObjectMapper> mapperByName = > mappersByName > .entrySet() > .iterator() > .next(); > objectMapper = mapperByName.getValue(); > LOG.debug("doStart: Using objectMapper=[name:{}, {}]", > mapperByName.getKey(), objectMapper); > } > } > if (objectMapper == null) { > objectMapper = new ObjectMapper(); > LOG.warn("doStart: Using new default objectMapper={}", > objectMapper); > } > } > ... > {code} > An enhancement to this would be to allow the *bean name* to be specified > instead of simply choosing the first one found. -- This message was sent by Atlassian JIRA (v6.4.14#64029)