本文整理汇总了Java中org.bson.BsonWriter.writeNull方法的典型用法代码示例。如果您正苦于以下问题:Java BsonWriter.writeNull方法的具体用法?Java BsonWriter.writeNull怎么用?Java BsonWriter.writeNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.writeNull方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
}
}
示例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();
}
}