ZonedDateTime --> unable to use Codec
See original GitHub issuein Morphia 1.x versions, Used Converter for ZonedDateTime class (java.time). Stored this as String in Mongo DB with help of converter.
Starting with Morphia-core 2.2.3, Unable to configure Codec for ZonedDateTime.
Getting following exception:
org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec. Decoding into a 'ZonedDateTime' failed with the following exception: Cannot find a public constructor for 'ZonedDateTime'. A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type. at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:40) at org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:96) at dev.morphia.mapping.codec.pojo.EntityDecoder.decodeModel(EntityDecoder.java:59) at dev.morphia.mapping.codec.pojo.EntityDecoder.decodeProperties(EntityDecoder.java:80) at dev.morphia.mapping.codec.pojo.EntityDecoder.decode(EntityDecoder.java:35) at dev.morphia.mapping.codec.pojo.MorphiaCodec.decode(MorphiaCodec.java:71) at dev.morphia.mapping.codec.pojo.EntityDecoder.decode(EntityDecoder.java:40) at dev.morphia.mapping.codec.pojo.MorphiaCodec.decode(MorphiaCodec.java:71) at com.mongodb.internal.operation.CommandResultArrayCodec.decode(CommandResultArrayCodec.java:52) at com.mongodb.internal.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:60) at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87) at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42) at org.bson.internal.LazyCodec.decode(LazyCodec.java:48) at org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:104) at com.mongodb.internal.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:63) at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87) at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42) at com.mongodb.internal.connection.ReplyMessage.<init>(ReplyMessage.java:51) at com.mongodb.internal.connection.InternalStreamConnection.getCommandResult(InternalStreamConnection.java:540) at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:425) at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:342) at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:116) at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:647) at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:71) at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:244) at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:227) at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:127) at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:117) at com.mongodb.internal.connection.DefaultServer$OperationCountTrackingConnection.command(DefaultServer.java:348) at com.mongodb.internal.operation.CommandOperationHelper.createReadCommandAndExecute(CommandOperationHelper.java:228) at com.mongodb.internal.operation.FindOperation.lambda$execute$1(FindOperation.java:666) at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$2(OperationHelper.java:564) at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589) at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$3(OperationHelper.java:563) at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589) at com.mongodb.internal.operation.OperationHelper.withSourceAndConnection(OperationHelper.java:562) at com.mongodb.internal.operation.FindOperation.lambda$execute$2(FindOperation.java:661) at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:65) at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:692) at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:86) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:191) at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135) at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92) at dev.morphia.query.MorphiaQuery.prepareCursor(MorphiaQuery.java:321) at dev.morphia.query.MorphiaQuery.iterator(MorphiaQuery.java:200) at com.ghx.data.mongo.EmployeeDAO.findAll(QuickTourTest.java:397) at com.ghx.data.mongo.QuickTourTest.demo(QuickTourTest.java:149) Caused by: org.bson.codecs.configuration.CodecConfigurationException: Cannot find a public constructor for 'ZonedDateTime'. at org.bson.codecs.pojo.CreatorExecutable.checkHasAnExecutable(CreatorExecutable.java:140) at org.bson.codecs.pojo.CreatorExecutable.getInstance(CreatorExecutable.java:107) at org.bson.codecs.pojo.InstanceCreatorImpl.<init>(InstanceCreatorImpl.java:40) at org.bson.codecs.pojo.InstanceCreatorFactoryImpl.create(InstanceCreatorFactoryImpl.java:28) at org.bson.codecs.pojo.ClassModel.getInstanceCreator(ClassModel.java:75) at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:102) at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:107) at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:37) ... 83 more
Morphia Version:2.2.3
Issue Analytics
- State:
- Created a year ago
- Comments:6 (5 by maintainers)
Oh, for sure. My intent was simply that conversion of such types would be more appropriate at the driver level or a custom codec rather than Morphia whose concern is a step higher. Wit the other types encoded by the driver, it seemed the more appropriate place. But that’s the beauty of the codecs: anyone can add one to the system to fill in the gaps.
Morphia 1.x had
Converter
types but the API was fragile and was supplanted by the codecs.Since there appears to be no other questions at the moment, I’m going to close this as answered. If you need starter tips on writing a custom codec, I’m happy to help.