本文整理汇总了Java中org.bson.BsonWriter.writeEndDocument方法的典型用法代码示例。如果您正苦于以下问题:Java BsonWriter.writeEndDocument方法的具体用法?Java BsonWriter.writeEndDocument怎么用?Java BsonWriter.writeEndDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.writeEndDocument方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import org.bson.BsonWriter; //导入方法依赖的package包/类
@Override
public void encode(BsonWriter writer, T map, EncoderContext encoderContext) {
if (map == null) {
writer.writeNull();
}
else {
writer.writeStartDocument();
for (Map.Entry<String, Object> entry : map.entrySet()) {
writer.writeName(entry.getKey());
Object value = entry.getValue();
Codec fieldMappingCodec = fieldMappingCodecs.get(entry.getKey());
if (fieldMappingCodec != null) {
fieldMappingCodec.encode(writer, value, encoderContext);
} else {
if (value != null) {
Codec codec = codecRegistry.get(value.getClass());
codec.encode(writer, value, encoderContext);
} else {
writer.writeNull();
}
}
}
writer.writeEndDocument();
}
}
示例2: encode
import org.bson.BsonWriter; //导入方法依赖的package包/类
@Override
public void encode(BsonWriter writer, T value, EncoderContext encoderContext) {
if (value == null) {
writer.writeNull();
}
else {
writer.writeStartDocument();
PolymorphicCodec<T> codecForValue = getCodecForClass(value.getClass());
if (codecForValue != null) {
writer.writeName(discriminatorKeys.get(codecForValue.getEncoderClass()));
writer.writeString(mainDiscriminators.get(codecForValue.getEncoderClass()));
codecForValue.encodeFields(writer, value, encoderContext);
} else {
LOGGER.warn("The value to be encoded has the wrong type {}. This codec can only handle {}", value.getClass(), discriminatorToCodec);
}
writer.writeEndDocument();
}
}
示例3: encodeFields
import org.bson.BsonWriter; //导入方法依赖的package包/类
@Override
public void encodeFields(BsonWriter writer, T instance, EncoderContext encoderContext) {
// first persist meta document
documentMetaCodec.encodeFields(writer, instance.getMeta(), encoderContext);
// only persist data property if and only if properties exist
Map<String, MappedField> persistenceFields = getPersistenceFields();
if (!persistenceFields.isEmpty()) {
writer.writeName("data");
writer.writeStartDocument();
for (MappedField persistenceField : persistenceFields.values()) {
if (!"meta".equals(persistenceField.getMappedFieldName())) {
persistenceField.encode(writer, instance, encoderContext);
}
}
writer.writeEndDocument();
}
}
示例4: encode
import org.bson.BsonWriter; //导入方法依赖的package包/类
@Override
default void encode(BsonWriter writer, T value, EncoderContext encoderContext) {
if (value == null) {
writer.writeNull();
}
else {
writer.writeStartDocument();
encodeFields(writer, value, encoderContext);
writer.writeEndDocument();
}
}
示例5: encode
import org.bson.BsonWriter; //导入方法依赖的package包/类
@Override
public void encode(BsonWriter writer, Map<String, V> map, EncoderContext encoderContext) {
writer.writeStartDocument();
for (Map.Entry<String, V> entry : map.entrySet()) {
writer.writeName(entry.getKey());
valueTypeCodec.encode(writer, entry.getValue(), encoderContext);
}
writer.writeEndDocument();
}
示例6: encode
import org.bson.BsonWriter; //导入方法依赖的package包/类
@Override
public void encode(BsonWriter writer, Map<K, V> map, EncoderContext encoderContext) {
writer.writeStartArray();
for (Map.Entry<K, V> entry : map.entrySet()) {
writer.writeStartDocument();
writer.writeName("key");
keyTypeCodec.encode(writer, entry.getKey(), encoderContext);
writer.writeName("value");
valueTypeCodec.encode(writer, entry.getValue(), encoderContext);
writer.writeEndDocument();
}
writer.writeEndArray();
}
示例7: encode
import org.bson.BsonWriter; //导入方法依赖的package包/类
@Override
public void encode(BsonWriter writer, CustomType<T> value, EncoderContext encoderContext) {
writer.writeStartDocument();
writer.writeName("name");
nameCodec.encode(writer, value.getANameForTheList(), encoderContext);
writer.writeName("list");
listCodec.encode(writer, value, encoderContext);
writer.writeName("innerType");
innerTypeCodec.encode(writer, value.getInnerType(), encoderContext);
writer.writeEndDocument();
}
示例8: encode
import org.bson.BsonWriter; //导入方法依赖的package包/类
public void encode(BsonWriter bsonWriter, Object object) {
bsonWriter.writeStartDocument();
Map<String, Field> bsonNameFieldInfoMap = getBsonNameFieldInfoMap(object.getClass());
for (Entry<String, Field> entry : bsonNameFieldInfoMap.entrySet()) {
Field field = entry.getValue();
Object fieldValue = Utils.getFieldValue(field, object);
if (fieldValue == null || Utils.isIgnored(field)) {
continue;
}
String bsonName = entry.getKey();
bsonWriter.writeName(bsonName);
Class<?> fieldType = field.getType();
if (Utils.isArrayType(fieldType)) {
BsonValueConverterRepertory.getBsonArrayConverter().encode(bsonWriter, field, fieldValue);
continue;
}
if (BsonValueConverterRepertory.isCanConverterValueType(fieldType)) {
if (Utils.fieldIsObjectId(field)) {
if (fieldType == String.class) {
fieldValue = new StringObjectId(new ObjectId((String) fieldValue));
fieldType = StringObjectId.class;
}
}
BsonByteIOConverter<Object> valueConverter = BsonValueConverterRepertory.getByteIOConverterByClazz(fieldType);
if (valueConverter != null) {
valueConverter.encode(bsonWriter, fieldValue);
} else {
// maybe log warn message to remind user add converter
}
} else {
BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonWriter, fieldValue);
}
}
bsonWriter.writeEndDocument();
}