@@ -0,0 +1,1185 @@
+/**%0A * %0A */%0Apackage cn.strong.leke.data.mongo.codec;%0A%0Aimport org.bson.BsonReader;%0Aimport org.bson.BsonWriter;%0Aimport org.bson.Document;%0Aimport org.bson.codecs.Codec;%0Aimport org.bson.codecs.DecoderContext;%0Aimport org.bson.codecs.EncoderContext;%0Aimport org.bson.codecs.configuration.CodecRegistry;%0A%0Aimport cn.strong.leke.data.mongo.BsonUtils;%0A%0A/**%0A * JavaBean %E6%A8%A1%E5%9E%8B%E8%A7%A3%E7%BC%96%E7%A0%81%E5%99%A8%0A * %0A * @author liulongbiao%0A *%0A */%0Apublic class BeanCodec%3CT%3E implements Codec%3CT%3E %7B%0A%0A%09final CodecRegistry registry;%0A%09final Class%3CT%3E clazz;%0A%0A%09public BeanCodec(CodecRegistry registry, Class%3CT%3E clazz) %7B%0A%09%09super();%0A%09%09this.registry = registry;%0A%09%09this.clazz = clazz;%0A%09%7D%0A%0A%09@Override%0A%09public void encode(BsonWriter writer, T value, EncoderContext encoderContext) %7B%0A%09%09Document doc = BsonUtils.toBSON(value);%0A%09%09Codec%3CDocument%3E delegate = registry.get(Document.class);%0A%09%09delegate.encode(writer, doc, encoderContext);%0A%09%7D%0A%0A%09@Override%0A%09public Class%3CT%3E getEncoderClass() %7B%0A%09%09return clazz;%0A%09%7D%0A%0A%09@Override%0A%09public T decode(BsonReader reader, DecoderContext decoderContext) %7B%0A%09%09Codec%3CDocument%3E docCodec = registry.get(Document.class);%0A%09%09Document doc = docCodec.decode(reader, decoderContext);%0A%09%09return BsonUtils.fromBSON(doc, clazz);%0A%09%7D%0A%0A%7D%0A

添加 BeanCodec