本文整理汇总了Java中org.bson.BsonType.NULL属性的典型用法代码示例。如果您正苦于以下问题:Java BsonType.NULL属性的具体用法?Java BsonType.NULL怎么用?Java BsonType.NULL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bson.BsonType
的用法示例。
在下文中一共展示了BsonType.NULL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleArrayForBsonReader
private Object handleArrayForBsonReader(BsonReader bsonReader, Field field, BsonMapperConfig bsonMapperConfig) {
Class<?> fieldType = field.getType();
ArrayList<Object> arrayList = new ArrayList<Object>();
bsonReader.readStartArray();
while (bsonReader.readBsonType() != BsonType.END_OF_DOCUMENT) {
BsonType currentBsonType = bsonReader.getCurrentBsonType();
if (currentBsonType == BsonType.NULL) {
continue;
}
if (currentBsonType == BsonType.ARRAY) {
arrayList.add(decode(bsonReader, field, bsonMapperConfig));
} else {
Object javaValue;
if (currentBsonType == BsonType.DOCUMENT) {
javaValue = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonReader, fieldType.getComponentType(), bsonMapperConfig);
} else {
javaValue = BsonValueConverterRepertory.getByteIOConverterByBsonType(currentBsonType).decode(bsonReader);
}
arrayList.add(javaValue);
}
}
bsonReader.readEndArray();
return arrayList.toArray((Object[]) Array.newInstance(fieldType.getComponentType(), 0));
}
示例2: decode
public void decode(BsonReader reader, T instance, DecoderContext decoderContext) {
LOGGER.debug("Decode field : " + getMappedFieldName() + " Signature: " + fieldTypePair.getRealType());
if (field.getType().isPrimitive()) {
if (reader.getCurrentBsonType() == BsonType.NULL || reader.getCurrentBsonType() == BsonType.UNDEFINED) {
reader.skipValue();
} else {
primitiveType.decode(reader, instance, decoderContext, this);
}
} else if (codec != null) {
if (reader.getCurrentBsonType() == BsonType.NULL ) {
reader.readNull();
setFieldValue(instance, null);
}
else if (reader.getCurrentBsonType() == BsonType.UNDEFINED) {
reader.skipValue();
}
else {
F decoded = codec.decode(reader, decoderContext);
setFieldValue(instance, decoded);
}
}
}
示例3: read
public T read(BsonReader reader, String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.STRING) {
String enumValue = reader.readString();
T value = decodingMappings.get(enumValue);
if (value == null) throw Exceptions.error("can not decode value to enum, enumClass={}, value={}", enumClass.getCanonicalName(), enumValue);
return value;
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}
示例4: readValue
@SuppressWarnings("unchecked")
public <U> U readValue(final BsonReader reader,
final DecoderContext decoderContext) {
BsonType bsonType = reader.getCurrentBsonType();
if (bsonType == BsonType.NULL) {
reader.readNull();
return null;
} else if (bsonType == BsonType.ARRAY) {
return (U) readList(reader, decoderContext);
} else if (bsonType == BsonType.BINARY) {
byte bsonSubType = reader.peekBinarySubType();
if (bsonSubType == BsonBinarySubType.UUID_STANDARD.getValue()
|| bsonSubType == BsonBinarySubType.UUID_LEGACY.getValue()) {
return (U) registry.get().get(UUID.class).decode(reader,
decoderContext);
}
}
return (U) registry.get().get(bsonTypeClassMap.get(bsonType)).decode(reader,
decoderContext);
}
示例5: getBsonType
protected BsonType getBsonType(Object value) {
if (value == null) {
return BsonType.NULL;
} else if (value instanceof Boolean) {
return BsonType.BOOLEAN;
} else if (value instanceof Double) {
return BsonType.DOUBLE;
} else if (value instanceof Integer) {
return BsonType.INT32;
} else if (value instanceof Long) {
return BsonType.INT64;
} else if (value instanceof String) {
return BsonType.STRING;
} else if (isObjectIdInstance(value)) {
return BsonType.OBJECT_ID;
} else if (isObjectInstance(value)) {
return BsonType.DOCUMENT;
} else if (isArrayInstance(value)) {
return BsonType.ARRAY;
} else {
return null;
}
}
示例6: decode
@Override
public List decode( final BsonReader reader, final DecoderContext decoderContext )
{
reader.readStartArray();
List list = new ArrayList();
while ( reader.readBsonType() != BsonType.END_OF_DOCUMENT )
{
Object value;
if ( reader.getCurrentBsonType() == BsonType.NULL )
{
reader.readNull();
value = null;
}
else
{
value = registry.get( bsonTypeClassMap.get( reader.getCurrentBsonType() ) ).decode( reader,
decoderContext );
}
list.add( value );
}
reader.readEndArray();
return list;
}
示例7: readValue
private Object readValue(final BsonReader reader, final DecoderContext decoderContext) {
BsonType bsonType = reader.getCurrentBsonType();
if (bsonType == BsonType.NULL) {
reader.readNull();
return null;
} else if (bsonType == BsonType.ARRAY) {
return readList(reader, decoderContext);
} else if (bsonType == BsonType.BINARY && BsonBinarySubType.isUuid(reader.peekBinarySubType()) && reader.peekBinarySize() == 16) {
return codecRegistry.get(UUID.class).decode(reader, decoderContext);
}
return bsonTypeCodecMap.get(bsonType).decode(reader, decoderContext);
}
示例8: decode
/**
* bsonReader中读取Bson到POJO/decode from bsonReader->POJO
*
* @param bsonReader
* @param targetClazz
* @param bsonMapperConfig
* @param <T>
* @return
*/
<T> T decode(BsonReader bsonReader, Class<T> targetClazz, BsonMapperConfig bsonMapperConfig) {
MAPPER_LAYER_COUNTER.addCount(bsonMapperConfig);
try {
bsonReader.readStartDocument();
Map<String, Field> bsonNameFieldInfoMap = getBsonNameFieldInfoMap(targetClazz);
T target = Utils.newInstanceByClazz(targetClazz);
while (bsonReader.readBsonType() != BsonType.END_OF_DOCUMENT) {
String bsonName = bsonReader.readName();
Field field = bsonNameFieldInfoMap.get(bsonName);
if (field == null || bsonReader.getCurrentBsonType() == BsonType.NULL) {
bsonReader.skipValue();
continue;
}
Object javaValue;
try {
javaValue = getJavaValueByBinaryReader(bsonReader, field, bsonMapperConfig);
} catch (BsonMapperConverterException e) {
throw new BsonMapperConverterException("error when try to get java value from Bson.BsonName:" + bsonName, e);
}
setJavaValueToField(targetClazz, target, field, javaValue);
}
bsonReader.readEndDocument();
return target;
} finally {
MAPPER_LAYER_COUNTER.reduceCount();
}
}
示例9: handleCollectionForBsonReader
Object handleCollectionForBsonReader(BsonReader bsonReader, Field field, BsonMapperConfig bsonMapperConfig) {
Class<?> fieldType = field.getType();
Class<?> implClass = Utils.giveImplClassIfSupport(fieldType);
if (Utils.isUnableAddCollectionClazz(implClass)) {
return null;
}
BsonArrayField bsonArrayField = Utils.getBsonArrayFieldAnnotation(field);
Class<?> targetComponentClazz = bsonArrayField.componentType();
Object collectionObject = Utils.newInstanceByClazz(implClass);
Method method;
try {
method = implClass.getMethod("add", Object.class);
} catch (NoSuchMethodException e) {
throw new BsonMapperConverterException("NoSuchMethodException", e);
}
bsonReader.readStartArray();
while (bsonReader.readBsonType() != BsonType.END_OF_DOCUMENT) {
BsonType currentBsonType = bsonReader.getCurrentBsonType();
if (currentBsonType == BsonType.NULL) {
continue;
}
if (currentBsonType == BsonType.ARRAY) {
Utils.methodInvoke(method, collectionObject, decode(bsonReader, field, bsonMapperConfig));
} else {
Object javaValue;
if (currentBsonType == BsonType.DOCUMENT) {
javaValue = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonReader, targetComponentClazz, bsonMapperConfig);
} else {
javaValue = BsonValueConverterRepertory.getByteIOConverterByBsonType(currentBsonType).decode(bsonReader);
}
Utils.methodInvoke(method, collectionObject, javaValue);
}
}
bsonReader.readEndArray();
return collectionObject;
}
示例10: readInteger
public Integer readInteger(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.INT32) {
return reader.readInt32();
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}
示例11: readObjectId
public ObjectId readObjectId(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.OBJECT_ID) {
return reader.readObjectId();
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}
示例12: readLong
public Long readLong(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.INT32) {
return (long) reader.readInt32();
} else if (currentType == BsonType.INT64) {
return reader.readInt64();
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}
示例13: readString
public String readString(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.STRING) {
return reader.readString();
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}
示例14: readDouble
public Double readDouble(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.DOUBLE) {
return reader.readDouble();
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}
示例15: readBoolean
public Boolean readBoolean(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.BOOLEAN) {
return reader.readBoolean();
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}