Skip to content

Can't find a codec for class java.time.Instant #3968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Feb 18, 2022 · 2 comments
Closed

Can't find a codec for class java.time.Instant #3968

ghost opened this issue Feb 18, 2022 · 2 comments
Assignees
Labels
type: bug A general bug

Comments

@ghost
Copy link

ghost commented Feb 18, 2022

Hello,

I'm working on developing authentication system with
spring session mongodb and spring data mongodb reactive.

After I login a session successfully, every time an exception is occured.
The error message is as follow.

It says java.time.Instant is not found.

Is this a bug ?

SLF4J: Failed toString() invocation on an object of type [com.mongodb.BasicDBObject]
Reported exception:
org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.Instant.
	at org.bson.internal.CodecCache.lambda$getOrThrow$1(CodecCache.java:52)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at org.bson.internal.CodecCache.getOrThrow(CodecCache.java:51)
	at org.bson.internal.OverridableUuidRepresentationCodecRegistry.get(OverridableUuidRepresentationCodecRegistry.java:72)
	at org.bson.internal.ChildCodecRegistry.get(ChildCodecRegistry.java:52)
	at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:245)
	at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:159)
	at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:67)
	at com.mongodb.BasicDBObject.toJson(BasicDBObject.java:204)
	at com.mongodb.BasicDBObject.toJson(BasicDBObject.java:177)
	at com.mongodb.BasicDBObject.toJson(BasicDBObject.java:164)
	at com.mongodb.BasicDBObject.toString(BasicDBObject.java:251)
	at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:277)
	at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:249)
	at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:211)
	at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:161)
	at ch.qos.logback.classic.spi.LoggingEvent.getFormattedMessage(LoggingEvent.java:293)
	at ch.qos.logback.classic.spi.LoggingEvent.prepareForDeferredProcessing(LoggingEvent.java:206)
	at ch.qos.logback.core.OutputStreamAppender.subAppend(OutputStreamAppender.java:223)
	at ch.qos.logback.core.OutputStreamAppender.append(OutputStreamAppender.java:102)
	at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:84)
	at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
	at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
	at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
	at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
	at ch.qos.logback.classic.Logger.filterAndLog_1(Logger.java:398)
	at ch.qos.logback.classic.Logger.debug(Logger.java:486)
	at org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener.onBeforeConvert(AbstractMongoEventListener.java:106)
	at org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener.onApplicationEvent(AbstractMongoEventListener.java:87)
	at org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener.onApplicationEvent(AbstractMongoEventListener.java:31)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
	at org.springframework.data.mongodb.core.ReactiveMongoTemplate.maybeEmitEvent(ReactiveMongoTemplate.java:2631)
	at org.springframework.data.mongodb.core.ReactiveMongoTemplate.lambda$doSave$52(ReactiveMongoTemplate.java:1535)
	at 
.....
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 18, 2022
@ghost
Copy link
Author

ghost commented Feb 18, 2022

I found the below code caused the error.

@Configuration
public class ConstraintConfig {
  @Bean
  public ValidatingMongoEventListener validatingMongoEventListener() {
    return new ValidatingMongoEventListener(validator());
  }

  @Bean
  public LocalValidatorFactoryBean validator() {
    return new LocalValidatorFactoryBean();
  }
}

@christophstrobl
Copy link
Member

@azmhyy2021 thanks for reporting!

@christophstrobl christophstrobl self-assigned this Feb 18, 2022
@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 18, 2022
christophstrobl added a commit that referenced this issue Feb 18, 2022
We now make sure that codec configuration will not cause an exception when debug logging is turned on.

Resolves: #3968
Original Pull Request: #3970
christophstrobl added a commit that referenced this issue Feb 18, 2022
We now make sure that codec configuration will not cause an exception when debug logging is turned on.

Resolves: #3968
Original Pull Request: #3970
christophstrobl added a commit that referenced this issue Feb 18, 2022
We now make sure that codec configuration will not cause an exception when debug logging is turned on.

Resolves: #3968
Original Pull Request: #3970
@christophstrobl christophstrobl added this to the 3.2.9 (2021.0.9) milestone Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
2 participants