org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.ZonedDateTime.

Stack Overflow | pDer666 | 4 months ago
  1. 0

    MongoRepository findAll with ZonedDateTime predicate runs into CodecConfigurationException

    Stack Overflow | 4 months ago | pDer666
    org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.ZonedDateTime.
  2. 0

    Suppose we have a class and a repository declaration using QueryDsl {code} public class MyDocument { … ZonedDateTime remoteTime; … } public interface MyRepository extends MongoRepository<MyDocument, String>, QueryDslPredicateExecutor<MyDocument>{} {code} if the document is queried with {code} ZonedDateTime now = ZonedDateTime.now(); repository.findAll(QMyDocument.myDocument.remoteTime.between(now.minusDays(1), now.plusDays(1))); {code} then following exception is thrown: {code} org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.ZonedDateTime. at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37) at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:210) at com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:220) at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:196) at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:128) at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29) at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91) at org.bson.codecs.BsonDocumentCodec.writeValue(BsonDocumentCodec.java:133) at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:112) at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:40) at com.mongodb.connection.RequestMessage.addDocument(RequestMessage.java:253) at com.mongodb.connection.RequestMessage.addDocument(RequestMessage.java:205) at com.mongodb.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:75) at com.mongodb.connection.RequestMessage.encodeWithMetadata(RequestMessage.java:160) at com.mongodb.connection.CommandProtocol.sendMessage(CommandProtocol.java:192) at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:111) at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159) at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286) at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:173) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:215) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:206) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:112) at com.mongodb.operation.CountOperation$1.call(CountOperation.java:210) at com.mongodb.operation.CountOperation$1.call(CountOperation.java:206) at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:230) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:203) at com.mongodb.operation.CountOperation.execute(CountOperation.java:206) at com.mongodb.operation.CountOperation.execute(CountOperation.java:53) at com.mongodb.Mongo.execute(Mongo.java:772) at com.mongodb.Mongo$2.execute(Mongo.java:759) at com.mongodb.DBCollection.getCount(DBCollection.java:962) at com.mongodb.DBCollection.getCount(DBCollection.java:937) at com.mongodb.DBCollection.getCount(DBCollection.java:931) at com.mongodb.DBCollection.getCount(DBCollection.java:914) at com.mongodb.DBCollection.getCount(DBCollection.java:885) at com.mongodb.DBCollection.count(DBCollection.java:824) at com.querydsl.mongodb.AbstractMongodbQuery.fetchCount(AbstractMongodbQuery.java:391) at com.querydsl.mongodb.AbstractMongodbQuery.fetchResults(AbstractMongodbQuery.java:376) at org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.findAll(QueryDslMongoRepository.java:104) at org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.findAll(QueryDslMongoRepository.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) at com.sun.proxy.$Proxy69.findAll(Unknown Source) at com.favendo.squirrel.persistence.CrudNutRepositoryTests.readTimeFrame(CrudNutRepositoryTests.java:83) {code}

    Spring JIRA | 4 months ago | Mark Paluch
    org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.ZonedDateTime.
  3. 0

    spring mongo querydsl Can't find a codec for class java.time.LocalDateTime

    Stack Overflow | 1 month ago | Kery Hu
    org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.LocalDateTime.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Custom MapOfValuesConverter for dealing with key values containg restricted characters (., $)

    Google Groups | 1 year ago | Tom
    org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.frequentis.ps.persistence.mongo.integration.model.pojo.model.ComplexValue.

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.bson.codecs.configuration.CodecConfigurationException

      Can't find a codec for class java.time.ZonedDateTime.

      at org.bson.codecs.configuration.CodecCache.getOrThrow()
    2. MongoDB Java Driver
      DBCollection.count
      1. org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)
      2. org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)
      3. org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
      4. com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:210)
      5. com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:220)
      6. com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:196)
      7. com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:128)
      8. com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61)
      9. org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
      10. org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
      11. org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
      12. org.bson.codecs.BsonDocumentCodec.writeValue(BsonDocumentCodec.java:133)
      13. org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:112)
      14. org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:40)
      15. com.mongodb.connection.RequestMessage.addDocument(RequestMessage.java:253)
      16. com.mongodb.connection.RequestMessage.addDocument(RequestMessage.java:205)
      17. com.mongodb.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:75)
      18. com.mongodb.connection.RequestMessage.encodeWithMetadata(RequestMessage.java:160)
      19. com.mongodb.connection.CommandProtocol.sendMessage(CommandProtocol.java:192)
      20. com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:111)
      21. com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159)
      22. com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286)
      23. com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:173)
      24. com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:215)
      25. com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:206)
      26. com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:112)
      27. com.mongodb.operation.CountOperation$1.call(CountOperation.java:210)
      28. com.mongodb.operation.CountOperation$1.call(CountOperation.java:206)
      29. com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:230)
      30. com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:203)
      31. com.mongodb.operation.CountOperation.execute(CountOperation.java:206)
      32. com.mongodb.operation.CountOperation.execute(CountOperation.java:53)
      33. com.mongodb.Mongo.execute(Mongo.java:772)
      34. com.mongodb.Mongo$2.execute(Mongo.java:759)
      35. com.mongodb.DBCollection.getCount(DBCollection.java:962)
      36. com.mongodb.DBCollection.getCount(DBCollection.java:937)
      37. com.mongodb.DBCollection.getCount(DBCollection.java:931)
      38. com.mongodb.DBCollection.getCount(DBCollection.java:914)
      39. com.mongodb.DBCollection.getCount(DBCollection.java:885)
      40. com.mongodb.DBCollection.count(DBCollection.java:824)
      40 frames
    3. com.querydsl.mongodb
      AbstractMongodbQuery.fetchResults
      1. com.querydsl.mongodb.AbstractMongodbQuery.fetchCount(AbstractMongodbQuery.java:391)
      2. com.querydsl.mongodb.AbstractMongodbQuery.fetchResults(AbstractMongodbQuery.java:376)
      2 frames
    4. Spring Data MongoDB - Core
      QueryDslMongoRepository.findAll
      1. org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.findAll(QueryDslMongoRepository.java:104)
      2. org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.findAll(QueryDslMongoRepository.java:50)
      2 frames
    5. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:498)
      4 frames
    6. Spring Data Core
      RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke
      1. org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503)
      2. org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488)
      3. org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
      3 frames
    7. Spring AOP
      ReflectiveMethodInvocation.proceed
      1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      1 frame
    8. org.springframework.data
      DefaultMethodInvokingMethodInterceptor.invoke
      1. org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
      1 frame
    9. Spring AOP
      JdkDynamicAopProxy.invoke
      1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      2. org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
      3. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      4. org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
      4 frames
    10. com.sun.proxy
      $Proxy69.findAll
      1. com.sun.proxy.$Proxy69.findAll(Unknown Source)
      1 frame
    11. com.favendo.squirrel
      CrudNutRepositoryTests.readTimeFrame
      1. com.favendo.squirrel.persistence.CrudNutRepositoryTests.readTimeFrame(CrudNutRepositoryTests.java:83)
      1 frame
    12. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:498)
      4 frames
    13. JUnit
      RunBefores.evaluate
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      5. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      5 frames
    14. Spring TestContext
      RunBeforeTestMethodCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
      1 frame
    15. JUnit
      RunAfters.evaluate
      1. org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      1 frame
    16. Spring TestContext
      SpringRepeat.evaluate
      1. org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
      2. org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
      2 frames
    17. JUnit
      ParentRunner.runLeaf
      1. org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      1 frame
    18. Spring TestContext
      SpringJUnit4ClassRunner.runChild
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
      2. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
      2 frames
    19. JUnit
      ParentRunner$2.evaluate
      1. org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      2. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      3. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      4. org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      5. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      5 frames
    20. Spring TestContext
      RunAfterTestClassCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      2 frames
    21. JUnit
      ParentRunner.run
      1. org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      1 frame
    22. Spring TestContext
      SpringJUnit4ClassRunner.run
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
      1 frame
    23. JUnit4 Runner
      JUnit4TestReference.run
      1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      1 frame
    24. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
      5 frames