@@ -0,0 +1,2176 @@
+/**%0A * %0A */%0Apackage cn.strong.leke.data.mongo.convert;%0A%0Aimport java.math.BigInteger;%0A%0Aimport org.bson.types.ObjectId;%0Aimport org.springframework.beans.factory.InitializingBean;%0Aimport org.springframework.core.convert.ConversionService;%0Aimport org.springframework.core.convert.converter.Converter;%0Aimport org.springframework.core.convert.support.DefaultConversionService;%0Aimport org.springframework.core.convert.support.GenericConversionService;%0A%0Aimport cn.strong.leke.data.mongo.convert.BsonConverters.BigIntegerToObjectIdConverter;%0Aimport cn.strong.leke.data.mongo.convert.BsonConverters.ObjectIdToBigIntegerConverter;%0Aimport cn.strong.leke.data.mongo.convert.BsonConverters.ObjectIdToStringConverter;%0Aimport cn.strong.leke.data.mongo.convert.BsonConverters.StringToObjectIdConverter;%0A%0A/**%0A * %E6%8A%BD%E8%B1%A1 BsonConverter %E5%AE%9E%E7%8E%B0%0A * %0A * @author liulongbiao%0A *%0A */%0Apublic abstract class AbstractBsonConverter implements BsonConverter, InitializingBean %7B%0A%09protected final GenericConversionService conversionService;%0A%09protected CustomConversions conversions = new CustomConversions();%0A%0A%09public AbstractBsonConverter(GenericConversionService conversionService) %7B%0A%09%09this.conversionService = conversionService == null ? new DefaultConversionService()%0A%09%09%09%09: conversionService;%0A%09%7D%0A%0A%09public void setCustomConversions(CustomConversions conversions) %7B%0A%09%09this.conversions = conversions;%0A%09%7D%0A%0A%09private void initializeConverters() %7B%0A%09%09putIfAbsent(ObjectId.class, String.class, ObjectIdToStringConverter.INSTANCE);%0A%09%09putIfAbsent(String.class, ObjectId.class, StringToObjectIdConverter.INSTANCE);%0A%09%09putIfAbsent(ObjectId.class, BigInteger.class, ObjectIdToBigIntegerConverter.INSTANCE);%0A%09%09putIfAbsent(BigInteger.class, ObjectId.class, BigIntegerToObjectIdConverter.INSTANCE);%0A%0A%09%09conversions.registerConvertersIn(conversionService);%0A%09%7D%0A%0A%09private %3CS, T%3E void putIfAbsent(Class%3CS%3E sourceType, Class%3CT%3E targetType,%0A%09%09%09Converter%3CS, T%3E converter) %7B%0A%09%09if (!conversionService.canConvert(sourceType, targetType)) %7B%0A%09%09%09conversionService.addConverter(converter);%0A%09%09%7D%0A%09%7D%0A%0A%09public ConversionService getConversionService() %7B%0A%09%09return conversionService;%0A%09%7D%0A%0A%09public void afterPropertiesSet() %7B%0A%09%09initializeConverters();%0A%09%7D%0A%7D%0A

添加 AbstractBsonConverter