12

I'm using Apache Camel 2.13.1 and MongoDB 2.2.2. I have the following route:

<route id="camel-route" autoStartup="true">
    <from uri="file:/dir?move=${date:now:yyyyMMdd}\processed\${file:name}&amp;moveFailed=${date:now:yyyyMMdd}\failed\${file:name}" />

    <unmarshal>
        <jaxb prettyPrint="false" contextPath="com.example.model" />
    </unmarshal>

    <to uri="mongodb:connectionBean?database=db&amp;collection=coll&amp;operation=save" />
</route>

The file consumer endpoint takes an XML file and unmarshall it to a POJO that contains several fields with data type int, String and java.util.Date. It saves/insert fine but the date field is saved as type NumberLong, instead of type ISODate.

But if I save it by using the MongoDB Java driver (i.e. creating DBObject, map a key with a field "new Date()"), it will save as ISODate in MongoDB. Any way I can do this by just using camel XML DSL?

EDIT: Digging into the codes and documentation, camel-mongodb is using Jackson that first will convert it to a Map, then to a BasicDBObject. Is there a way in the XML DSL I can configure the behaviour of Jackson? Last resort would be to write a custom type converter.

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
allancth
  • 300
  • 3
  • 15
  • [Related answer](https://stackoverflow.com/a/26071653/750510). Looks like you'll need a type converter. – madhead Nov 12 '17 at 10:51
  • Try to configure JacksonDataFormat (=the default format if no impl/library is specified) in order to set `write-date-as-timestamp` to false – TacheDeChoco May 16 '22 at 14:30

0 Answers0