Hi Ron,

This is a very good question. It's more a MongoDB-specific question rather
than a Camel question, but here's what I know of the topic.

Take into account that the JSON spec doesn't define a standard
date/dateTime format (unlike XSD), hence there's no universal way to
recognise a JSON value as a date. Moreover, MongoDB extends JSON with a
number of custom types, amongst which is the ISODate type.

It looks like the MongoDB JSON.parse(s) method interprets keys with the
special operator "$date" as dates. See [1]. You could modify your JSON data
model classes and add a few @Annotations so that Jackson already spits out
a $date field.

If you don't want to pollute your data model with MongoDB specific quirks,
you can post-process the "normal" JSON in a number of ways.

1) Manipulate at the BasicDBObject level, e.g.:

.process(new Processor() {
    public void process(Exchange exchange) {
       BasicDBObject bdbo = (BasicDBObject)
exchange.getIn().getBody(DBObject.class);
       // do the DBO manipulation, turn the date into an ISODate
       bdbo.put("date", new Date(...));
    }
});

2) Massage at the JSON level, by turning the Jackson-generated JSON into a
HashMap using ObjectMapper, and adding an intermediate key "$date", for
MongoDB's JSON parser to recognise the field as a date.

[1] https://jira.mongodb.org/browse/JAVA-565.

*Raúl Kripalani*
Apache Camel Committer
Enterprise Architect, Program Manager, Open Source Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk <http://twitter.com/raulvk>

On Thu, Feb 14, 2013 at 11:26 PM, Ron Anderson <biker_...@yahoo.com> wrote:

> Well it almost solved it.  It cured my exception and is now persisting the
> date in the database but it is storing it as a BSON string so still not
> recognized as an ISODate or BSON date type so no date functions yet work.
>
> Any way for the JSON date representation to get converted to BSON date
> type?
>
> thanks again,
>
> Ron
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/MongoDB-Jackson-Date-Mapping-Option-tp5727548p5727633.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply via email to