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


Java BsonType.NULL属性代码示例

本文整理汇总了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));
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:24,代码来源:BsonArrayConverter.java

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

示例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;
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:16,代码来源:EnumCodec.java

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

示例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;
  }
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:23,代码来源:AbstractJsonCodec.java

示例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;
}
 
开发者ID:cherimojava,项目名称:cherimodata,代码行数:23,代码来源:ListCodec.java

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

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

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

示例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;
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:13,代码来源:BsonReaderWrapper.java

示例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;
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:13,代码来源:BsonReaderWrapper.java

示例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;
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:15,代码来源:BsonReaderWrapper.java

示例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;
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:13,代码来源:BsonReaderWrapper.java

示例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;
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:13,代码来源:BsonReaderWrapper.java

示例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;
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:13,代码来源:BsonReaderWrapper.java


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