I've achieved this for Jackson as follows. I've no idea if this is a good
solution, but it works!:
1) Create a Spring Factory Bean for creating JacksonDataFormat instances.
i.e. <bean id="json-jackson" class="my.JacksonDataFormatFactory"/>
2) In my factory's getObject() method so something like:
ObjectMapper mapper = new ObjectMapper();
 //There are a bunch of properties than don't have matching getters &
setters. Ignore these on deserialisation.
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 //We need to include type info for properties of abstract types, so we can
deserialise them.
mapper.enableDefaultTyping();
 mapper.registerModule(new JacksonCustomisationModule());
JacksonDataFormat df = new JacksonDataFormat(mapper, null);
return df;

I use a custom Jackson SimpleModule where I register a number of mixins.
This allows me add some annotations to classes which are part of a
different project.

On 12 September 2014 22:35, rickaroni <rgfa...@directv.com> wrote:

> Hi,
>
> JSON libraries like Jackson and XStream provide ways of overriding the
> serializers/deserializers that get used for various specific object types.
>
> [While you can always hand-annotate code (e.g. with @JsonSerializer) to use
> custom serializers and deserializers, that can be cumbersome and invasive.]
>
> Some frameworks like Spring provide handy ways to do override the object to
> serializer/deserializer mappings:
>
> http://docs.spring.io/spring/docs/current/javadoc-api/index.html?org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.html
> <
> http://docs.spring.io/spring/docs/current/javadoc-api/index.html?org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.html
> >
>
> How can I do the same kind of thing in Camel to override the converters
> found in the the dataFormats section of camelContext?
>
> e.g. How do can I change the converters that get used to convert to/from
> MyObj1 and MyObj2 below?
>   <camelContext>
> ......
>       <dataFormats>
>           <json id="MyObj1MarshallingJSON"
> unmarshalTypeName="com.blah.bleh.MyObj1"  library="Jackson" />
>           <json id="MyObj2MarshallingJSON"
> unmarshalTypeName="com.blah.bleh.MyObj2"  library="XStream" />
>       </dataFormats>
>
> Thanks,
> Rick
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Over-riding-JSON-deserializers-serializers-in-Camel-w-o-using-annotations-tp5756458.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply via email to