当前位置: 首页>>代码示例>>Java>>正文


Java BsonWriter.writeName方法代码示例

本文整理汇总了Java中org.bson.BsonWriter.writeName方法的典型用法代码示例。如果您正苦于以下问题:Java BsonWriter.writeName方法的具体用法?Java BsonWriter.writeName怎么用?Java BsonWriter.writeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bson.BsonWriter的用法示例。


在下文中一共展示了BsonWriter.writeName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
    }
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:27,代码来源:SpecialFieldsMapCodec.java

示例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();
    }
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:19,代码来源:PolymorphicReflectionCodec.java

示例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();
    }
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:20,代码来源:CodecResolverTest.java

示例4: encode

import org.bson.BsonWriter; //导入方法依赖的package包/类
public void encode(BsonWriter writer, T instance, EncoderContext encoderContext) {
    LOGGER.debug("Encode field : " + getMappedFieldName());
    if (field.getType().isPrimitive()) {
        if (isLockingVersionField()) {
            writeLockingVersion(writer, instance);
        } else {
            primitiveType.encode(writer, instance, encoderContext, this);
        }
    } else if (codec != null) {
        F fieldValue = getFieldValue(instance);
        if (fieldValue == null) {
            switch (encodeNullHandlingStrategy) {
                case CODEC: {
                    if (codec instanceof TypeCodec) {
                        TypeCodec<F> typeCodec = (TypeCodec) codec;
                        fieldValue = typeCodec.defaultInstance();
                    }
                    break;
                }
                case KEEP_NULL:
                    break;

            }
        }

        if (encodeNulls || fieldValue != null) {
            writer.writeName(getMappedFieldName());
            if (fieldValue == null) {
                writer.writeNull();
            } else {
                codec.encode(writer, fieldValue, encoderContext);
            }
        }
    }
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:36,代码来源:MappedField.java

示例5: writeLockingVersion

import org.bson.BsonWriter; //导入方法依赖的package包/类
private void writeLockingVersion(BsonWriter writer, T instance) {
    try {
        writer.writeName(getMappedFieldName());
        int lockingVersion = field.getInt(instance) + 1;
        writer.writeInt32(lockingVersion);
    } catch (IllegalAccessException e) {
        LOGGER.warn("IllegalAccessException while writeLockingVersion field " + field.getName(), e);
    }
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:10,代码来源:MappedField.java

示例6: 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();
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:10,代码来源:SimpleMapTypeCodec.java

示例7: 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();
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:14,代码来源:ComplexMapTypeCodec.java

示例8: 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();
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:14,代码来源:TypeCodecProviderTest.java

示例9: 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();
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:36,代码来源:BsonDocumentConverter.java

示例10: encodeFields

import org.bson.BsonWriter; //导入方法依赖的package包/类
@Override
public void encodeFields(BsonWriter writer, T instance, EncoderContext encoderContext) {
    writer.writeName("enum");
    codec.encode(writer, instance, encoderContext);
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:6,代码来源:PojoContext.java


注:本文中的org.bson.BsonWriter.writeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。