camel-mongodb save java.util.Date as ISODate instead of NumberLong
Asked Answered
F

0

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.

Fong answered 9/7, 2014 at 3:36 Comment(2)
Related answer. Looks like you'll need a type converter.Intolerant
Try to configure JacksonDataFormat (=the default format if no impl/library is specified) in order to set write-date-as-timestamp to falseOndrej

© 2022 - 2024 — McMap. All rights reserved.