java Spring Data MongoDB字段转换器:有没有传递参数的方法?
当我们的应用程序从MongoDB加载一个DBObject/Document实例时,我们需要使用DBObject/Document实例中的zoneIdName将其中的所有UTC日期转换为ZoneDateTime值。DBObject中有很多日期字段,所以我不想实现DBObject级别的Spring Data MongoDB转换器
是否可以使用DBObject字段级Spring Data MongoDB转换器(如以下)来执行到ZoneDateTime的转换,该转换器使用DBObject中的字段(即zoneIdName)?如果没有,我将不得不实现一个对象级转换器,但这将是乏味的
感谢您的关注和时间
class ZonedDateTimeReadConverter :
Converter<Date, ZonedDateTime> {
override fun convert(date: Date): ZonedDateTime {
// Need to replace "America/LosAngeles" with
// a value from a field in the object being processed.
return date.toInstant().atZone(ZoneId.of("America/LosAngeles"))
}
}
# 1 楼答案
似乎整个对象的转换器是唯一的选择