1

I have been using the json, dataFormats, and marshall/unmarshall tags in the Camel Spring DSL as described in the following url and snippet from applicationContext.xml.

http://camel.apache.org/json.html

...

<dataFormats>
  <json id="json" library="Jackson" unmarshalTypeName="com.example.Foo" />
</dataFormats>

...

 <route>
     <from uri="direct:inPojo"/>
     <marshal ref="json"/>
 </route>
 <route>
     <from uri="direct:backPojo"/>
     <unmarshal ref="json"/>
 </route>

 ...

I want to serialize my joda DateTime objects as longs, as mentioned here:

http://wiki.fasterxml.com/JacksonFAQDateHandling

I understand that I need to register the separate Jackson-datatype-Joda module, and how to do that when I have an instance of an ObjectMapper, as mentioned in How to serialize Joda DateTime with Jackson JSON processer?, but is there a way to do it using the Camel/Spring XML tags?

Community
  • 1
  • 1
Chris Finley
  • 3,901
  • 5
  • 24
  • 32

1 Answers1

0

Pass in ObjectMapper to JacksonDataFormat. I'm not using Spring DSL, but you should be able to do the same thing like what I do in Java DSL:

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule( ... );
JacksonDataFormat df = new JacksonDataFormat(mapper, Pojo.class);
from("direct:source").unmarshal(df);
ceilfors
  • 2,617
  • 23
  • 33