¿No se pudo guardar el campo de fecha como fecha ISO en mongo db a través de Camel?

Tengo un pojo como este:

@Document(collection = "data")
public class DataPoint {
    @Id
    private String id;
    private LocalDateTime createdDate;
    ....
}

en alguna base de código tengo el siguiente código:

@Autowired
private ProducerTemplate producerTemplate;

...

final List<DataPoint> dataPoints =....
producerTemplate.sendBody("mongodb:mongoBean?database=" + mongoDataConfiguration.getDatabase()
                                    + "&createCollection=true&operation=insert&collection=" + mongoDataConfiguration.getDataPointCollection(), 
        dataPoints);

Pero cuando abro la colección en la base de datos, veo un campo de fecha como este:

"createdDate" : {
                "month" : "NOVEMBER",
                "year" : 2017,
                "dayOfMonth" : 7,
                "dayOfWeek" : "TUESDAY",
                "dayOfYear" : 311,
                "monthValue" : 11,
                "hour" : 17,
                "minute" : 55,
                "nano" : 259000000,
                "second" : 21,
                "chronology" : {
                        "id" : "ISO",
                        "calendarType" : "iso8601"
                }

Pero quiero almacenar la fecha ISO habitual reconocible para mongoDB. Debería ser algo como esto:

ISODate("2017-11-06T12:47:51.720")
¿Cómo intenté resolver este problema?

1:
Yo leoeste tema:

Así creé un serializador personalizado:

public class IsoDateSerializer extends JsonSerializer<DateTime> {
    @Override
    public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
           jgen.writeStartObject();
        serializeContents(value.toDate(), jgen, provider);
        jgen.writeEndObject();
    }
    private void serializeContents(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
        jgen.writeFieldName("$date");
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        String formattedDate = formatter.format(value);
        jgen.writeString(formattedDate);
    }
}

y lo registró correctamente:

@JsonSerialize(using = IsoDateSerializer.class)
public DateTime getCreatedDate() {
    return new DateTime(Date.from(createdDate.toInstant(ZoneOffset.UTC)));
}

Pero arroja una excepción:

org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-host-1510066910268-0-3]
        at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1847) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:713) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:515) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:511) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:163) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:168) ~[camel-core-2.20.0.jar:2.20.0]
        at com.debeers.mis.upload.route.DummyRoute$1.process(DummyRoute.java:113) ~[classes/:na]
        at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63) [camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) [camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:452) [camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:219) [camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:183) [camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174) [camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101) [camel-core-2.20.0.jar:2.20.0]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_111]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_111]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_111]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
    Caused by: org.apache.camel.component.mongodb.CamelMongoDbException: java.lang.IllegalArgumentException: Invalid BSON field name $date
        at org.apache.camel.component.mongodb.MongoDbComponent.wrapInCamelMongoDbException(MongoDbComponent.java:61) ~[camel-mongodb-2.20.0.jar:2.20.0]
        at org.apache.camel.component.mongodb.MongoDbProducer.process(MongoDbProducer.java:98) ~[camel-mongodb-2.20.0.jar:2.20.0]
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:186) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:86) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:541) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:506) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:369) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:506) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:229) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:144) ~[camel-core-2.20.0.jar:2.20.0]
        at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:161) ~[camel-core-2.20.0.jar:2.20.0]
        ... 18 common frames omitted
    Caused by: java.lang.IllegalArgumentException: Invalid BSON field name $date
        at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:516) ~[bson-3.4.3.jar:na]
        at com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:221) ~[mongodb-driver-3.4.3.jar:na]
        at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:198) ~[mongodb-driver-3.4.3.jar:na]
        at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:130) ~[mongodb-driver-3.4.3.jar:na]
        at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61) ~[mongodb-driver-3.4.3.jar:na]
        at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63) ~[bson-3.4.3.jar:na]
        at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29) ~[bson-3.4.3.jar:na]
        at com.mongodb.connection.InsertCommandMessage.writeTheWrites(InsertCommandMessage.java:101) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.InsertCommandMessage.writeTheWrites(InsertCommandMessage.java:43) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.BaseWriteCommandMessage.encodeMessageBodyWithMetadata(BaseWriteCommandMessage.java:129) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.RequestMessage.encodeWithMetadata(RequestMessage.java:160) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.WriteCommandProtocol.sendMessage(WriteCommandProtocol.java:220) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:101) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:67) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:37) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.connection.DefaultServerConnection.insertCommand(DefaultServerConnection.java:118) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.MixedBulkWriteOperation$Run$2.executeWriteCommandProtocol(MixedBulkWriteOperation.java:465) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.MixedBulkWriteOperation$Run$RunExecutor.execute(MixedBulkWriteOperation.java:656) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.MixedBulkWriteOperation$Run.execute(MixedBulkWriteOperation.java:411) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:177) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:168) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:426) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:417) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:168) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:74) ~[mongodb-driver-core-3.4.3.jar:na]
        at com.mongodb.Mongo.execute(Mongo.java:845) ~[mongodb-driver-3.4.3.jar:na]
        at com.mongodb.Mongo$2.execute(Mongo.java:828) ~[mongodb-driver-3.4.3.jar:na]
        at com.mongodb.MongoCollectionImpl.insertMany(MongoCollectionImpl.java:338) ~[mongodb-driver-3.4.3.jar:na]
        at com.mongodb.MongoCollectionImpl.insertMany(MongoCollectionImpl.java:322) ~[mongodb-driver-3.4.3.jar:na]
        at org.apache.camel.component.mongodb.MongoDbProducer.lambda$createDoInsert$7(MongoDbProducer.java:410) ~[camel-mongodb-2.20.0.jar:2.20.0]
        at org.apache.camel.component.mongodb.MongoDbProducer.lambda$wrap$0(MongoDbProducer.java:231) ~[camel-mongodb-2.20.0.jar:2.20.0]
        at org.apache.camel.component.mongodb.MongoDbProducer.invokeOperation(MongoDbProducer.java:112) ~[camel-mongodb-2.20.0.jar:2.20.0]
        at org.apache.camel.component.mongodb.MongoDbProducer.process(MongoDbProducer.java:96) ~[camel-mongodb-2.20.0.jar:2.20.0]
        ... 28 common frames omitted

Entonces necesito escribir:

 .marshal(jackson) 
        .convertBodyTo(String.class) 

pero pareceproducerTemplate no tiene la API adecuada

Ok, entiendo la causa de la excepción. @ @Neil Lunn dijo que es porque los nombres comenzaron con$ - reservado

2)

Creé un temaNo se pudo guardar el campo de fecha como fecha ISO en mongo db a través de Camel (causado por: java.lang.IllegalArgumentException: nombre de campo BSON no válido $ date)

Según @Neil Lunn consejos que intenté hacer

una) Fecha de devolución en el modelo:

public DateTime getCreatedDate() {
        return new DateTime(Date.from(createdDate.toInstant(ZoneOffset.UTC))).toDate();        
    }

Conduce a la fecha de guardado como NumberLong

si) trató de cambiar$date conmyDate en el serializador pero conduce a guardar la fecha como cadena habitual

с)

También intenté cambiar el formato de fecha en el serializador según @Neil Lunn advic en la pregunta anterior:

private void serializeContents(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeFieldName("mydate");
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    String formattedDate = formatter.format(value);
    jgen.writeString("ISODate("  +formattedDate + ")");
}

Pero todavía no funciona y veo:

"createdDate" : {
                "mydate" : "ISODate(2017-11-08T13:15:06)"
        },

en mongo-shell

¿Por favor, ayuda a luchar este problema?

PD

Cuando uso spring-data - las fechas se almacenan ahora sin movimientos adicionales

Respuestas a la pregunta(0)

Su respuesta a la pregunta