问题描述
我有这个简单的 Java 类型:
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class AnnotationSample {
private LocalDateTime startDate;
}
以下是 MongoDB 中保存的 AnnotationSample 类型的实例: The LocalDateTime field is stored with the Object type
当我尝试使用 Java/SpringBoot 找回 AnnotationSample 时,出现以下错误:
org.bson.codecs.configuration.CodecConfigurationException:使用 AutomaticPojoCodec 解码时发生异常。
解码为“AnnotationSample”失败,出现以下异常: 无法解码“AnnotationSample”。解码 'startDate' 出错:无法解码为 LocalDateTime,预期为 'DATE_TIME' BsonType 但得到了 'DOCUMENT'。
可能需要显式配置和注册自定义编解码器或 PojoCodec 以处理此类型。
我的依赖:
- org.mongodb:mongodb-driver-sync:4.3.0
- org.mongodb:mongodb-driver-async:3.12.9
- org.springframework.data:spring-data-mongodb:3.2.3
- org.springframework.data:spring-data-releasetrain:Neumann-SR7
- org.mongodb:bson:4.3.0
我使用了几乎可以在 Matrix 上找到的任何提示,但无济于事。我什至将此添加到我的配置中:
@Bean
public MongoCustomConversions mongoCustomConversions() {
return new MongoCustomConversions(new ArrayList<>(jsr310Converters.getConvertersToRegister()));
}
有人可以帮忙吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)