question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ZonedDateTime --> unable to use Codec

See original GitHub issue

in 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:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
evanchoolycommented, Jun 21, 2022

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.

0reactions
evanchoolycommented, Jul 9, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[JAVA-4653] ZonedDateTime --> unable to use Codec
Decoding into a 'ZonedDateTime' failed with the following exception: Cannot find a public constructor for 'ZonedDateTime'. A custom Codec or ...
Read more >
CodecConfigurationException when saving ZonedDateTime ...
My codec test branch is unable to unmarshal the data when using Spring Boot 2.0.5 while working fine with Spring Boot 2.0.1. public...
Read more >
CodecConfigurationException when saving ZonedDateTime ...
Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.ZonedDateTime. at org.bson.codecs.configuration ...
Read more >
ZonedDateTime (Java Platform SE 8 ) - Oracle Help Center
This will query the specified clock to obtain the current date-time. The zone and offset will be set based on the time-zone in...
Read more >
Optional codecs - DataStax Java Driver
LocalTimeCodec maps LocalTime to time . One problem with timestamp is that it does not store time zones. ZonedDateTimeCodec addresses that, by mapping...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found