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


Java BsonType类代码示例

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


BsonType类属于org.bson包,在下文中一共展示了BsonType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decode

import org.bson.BsonType; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
    T map = newInstance();
    reader.readStartDocument();
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        String key = reader.readName();

        Object value;
        Codec fieldMappingCodec = fieldMappingCodecs.get(key);
        if (fieldMappingCodec != null) {
            value = fieldMappingCodec.decode(reader, decoderContext);
        } else {
            value = readValue(reader, decoderContext);
        }

        map.put(key, value);
    }
    reader.readEndDocument();
    return map;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:21,代码来源:SpecialFieldsMapCodec.java

示例2: decode

import org.bson.BsonType; //导入依赖的package包/类
@Override
public Map<String, V> decode(BsonReader reader, DecoderContext decoderContext) {
    Map<String, V> map = newInstance();
    if (BsonType.DOCUMENT.equals(reader.getCurrentBsonType())) {
        reader.readStartDocument();
        while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
            String key = reader.readName();
            V value = valueTypeCodec.decode(reader, decoderContext);
            map.put(key, value);
        }
        reader.readEndDocument();
    } else {
        LOGGER.warn("Expected {} from reader but got {}. Skipping value.", BsonType.DOCUMENT, reader.getCurrentBsonType());
        reader.skipValue();
    }
    return map;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:18,代码来源:SimpleMapTypeCodec.java

示例3: decode

import org.bson.BsonType; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
    if (BsonType.STRING.equals(reader.getCurrentBsonType())) {
        String name = reader.readString();
        if (name != null) {
            try {
                return Enum.valueOf(clazz, name);
            } catch (IllegalArgumentException e) {
                LOGGER.warn("Enum value {} could not be determined for enum type {}", name, clazz, e);
            }
        }
    } else {
        LOGGER.warn("Expected {} from reader but got {}. Skipping value.", BsonType.STRING, reader.getCurrentBsonType());
        reader.skipValue();
    }
    return null;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:18,代码来源:EnumCodec.java

示例4: handleArrayForBsonReader

import org.bson.BsonType; //导入依赖的package包/类
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,代码行数:25,代码来源:BsonArrayConverter.java

示例5: scalarToString

import org.bson.BsonType; //导入依赖的package包/类
/**
 * Gson library reads numbers lazily when using generic {@link com.google.gson.internal.bind.TypeAdapters#JSON_ELEMENT} type adapter.
 * Number is read as string and then wrapped inside {@link LazilyParsedNumber}. This inefficiency should only occur if reading numbers with generic JSON element API
 * and not using generated type adapters.
 *
 * @see LazilyParsedNumber
 * @see com.google.gson.internal.bind.TypeAdapters#JSON_ELEMENT
 */
private String scalarToString() throws IOException {
  final BsonType type = delegate.getCurrentBsonType();

  if (type == BsonType.STRING) {
    return delegate.readString();
  } else if (type == BsonType.SYMBOL) {
    return delegate.readSymbol();
  } else if (type == BsonType.INT32) {
    return Integer.toString(nextInt());
  } else if (type == BsonType.INT64) {
    return Long.toString(nextLong());
  } else if (type == BsonType.DOUBLE) {
    return Double.toString(nextDouble());
  }

  throw new IllegalStateException(String.format("Unknown scalar type to be converted to string: %s", type));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:BsonReader.java

示例6: decode

import org.bson.BsonType; //导入依赖的package包/类
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,代码行数:23,代码来源:MappedField.java

示例7: decode

import org.bson.BsonType; //导入依赖的package包/类
@Override
public Map<K, V> decode(BsonReader reader, DecoderContext decoderContext) {
    Map<K, V> map = newInstance();
    if (BsonType.ARRAY.equals(reader.getCurrentBsonType())) {
        reader.readStartArray();
        while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
            if (BsonType.DOCUMENT.equals(reader.getCurrentBsonType())) {
                reader.readStartDocument();
                reader.readName(); // don't need the key == "key"
                K key = keyTypeCodec.decode(reader, decoderContext);
                reader.readName(); // don't need the key == "value"
                V value = valueTypeCodec.decode(reader, decoderContext);
                map.put(key, value);
                reader.readEndDocument();
            } else {
                LOGGER.warn("Expected {} from reader but got {}. Skipping value.", BsonType.DOCUMENT, reader.getCurrentBsonType());
                reader.skipValue();
            }
        }
        reader.readEndArray();
    } else {
        LOGGER.warn("Expected {} from reader but got {}. Skipping value.", BsonType.ARRAY, reader.getCurrentBsonType());
        reader.skipValue();
    }
    return map;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:27,代码来源:ComplexMapTypeCodec.java

示例8: decodeFields

import org.bson.BsonType; //导入依赖的package包/类
@Override
public T decodeFields(BsonReader reader, DecoderContext decoderContext, T instance) {
    MetaData documentMeta = instance.getMeta();
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        String fieldName = reader.readName();
        if ("data".equals(fieldName)) {
            reader.readStartDocument();
            super.decodeFields(reader, decoderContext, instance);
            reader.readEndDocument();
        } else {
            MappedField field = documentMetaCodec.getMappedField(fieldName);
            if (field != null) {
                field.decode(reader, documentMeta, decoderContext);
            } else {
                reader.skipValue();
            }
        }
    }

    documentMetaCodec.postDecode(documentMeta);

    return instance;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:24,代码来源:CodecResolverTest.java

示例9: method_decode_should_evocate_functions_that_reade_user_attributes

import org.bson.BsonType; //导入依赖的package包/类
@Test
public void method_decode_should_evocate_functions_that_reade_user_attributes() throws Exception {
    DecoderContext decoderContext = DecoderContext.builder().build();
    PowerMockito.when(reader.readString("password")).thenReturn(PASSWORD);
    PowerMockito.when(reader.readString("phone")).thenReturn(PHONE);
    PowerMockito.when(reader.readBoolean("enable")).thenReturn(ENABLE);
    PowerMockito.when(reader.readBoolean("extraction")).thenReturn(EXTRACTIONENABLED);
    PowerMockito.when(reader.readString("surname")).thenReturn(SURNAME);
    PowerMockito.when(reader.readString("name")).thenReturn(NAME);
    PowerMockito.when(reader.readBoolean("adm")).thenReturn(ADMIN);
    PowerMockito.when(reader.readString("uuid")).thenReturn(UUIDString);
    PowerMockito.when(reader.readString("email")).thenReturn(EMAIL);
    PowerMockito.when(reader.readString("acronym")).thenReturn(FIELDCENTERACRONYM);
    PowerMockito.when(reader.readBsonType()).thenReturn(BsonType.END_OF_DOCUMENT);
    doThrow(new BsonInvalidOperationException("teste")).when(reader).readNull("fieldCenter");
    doThrow(new BsonInvalidOperationException("teste")).when(reader).readNull("extraction");
    User userLocal = UserCodec.decode(reader,  decoderContext);
    assertEquals(userLocal.getEmail(),EMAIL);
    assertEquals(userLocal.getPassword(),PASSWORD);
    assertEquals(userLocal.getPhone(),PHONE);
    assertEquals(userLocal.isEnable(),ENABLE);
    assertEquals(userLocal.isExtractionEnabled(),EXTRACTIONENABLED);
    assertEquals(userLocal.getName(),NAME);
    assertEquals(userLocal.getFieldCenter().getAcronym(),FIELDCENTERACRONYM);
    assertEquals(userLocal.getUuid().toString(),UUID.fromString(UUIDString).toString());
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:27,代码来源:UserCodecTest.java

示例10: decode

import org.bson.BsonType; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	switch(type) {
	case INT32:
		return decode(reader.readInt32() != 0);
	case NULL:
		return null;
	case STRING:
		return decode(Boolean.parseBoolean(reader.readString()));
	case BOOLEAN:
		return decode(reader.readBoolean());
		//$CASES-OMITTED$
	default:
		final String errMsg = format("Invalid date type, found: %s", type);
		throw new BsonInvalidOperationException(errMsg); 
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:19,代码来源:AbstractBooleanCodec.java

示例11: decode

import org.bson.BsonType; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	switch(type) {
	case DATE_TIME:
		return decode(reader.readDateTime());
	case DOUBLE:
		return decode((long) reader.readDouble());
	case INT32:
		return decode(reader.readInt32());
	case INT64:
		return decode(reader.readInt64());
	case NULL:
		return null;
	case STRING:
		return decode(Long.valueOf(reader.readString()));
		//$CASES-OMITTED$
	default:
		final String errMsg = format("Invalid date type, found: %s", type);
		throw new BsonInvalidOperationException(errMsg); 
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:23,代码来源:AbstractTimeCodec.java

示例12: decode

import org.bson.BsonType; //导入依赖的package包/类
@Override
public TestBean decode(BsonReader reader, DecoderContext decoderContext) {
    reader.readStartDocument();
    TestBean pojo = new TestBean();
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        switch (reader.readName()) {
            case "stringField":
                pojo.setStringField(reader.getCurrentBsonType() != BsonType.NULL ? reader.readString() : null);
                break;
            case "longField":
                pojo.setLongField(reader.readInt64());
                break;
            case "listStringField":
                pojo.setListStringField(this.decodeGenericList(reader, decoderContext, String.class));
                break;
            case "setStringField":
                pojo.setSetStringField(this.decodeGenericSet(reader, decoderContext, String.class));
                break;
            default:
                Assert.fail("Unexpected name " + reader.getCurrentName());
        }
    }
    reader.readEndDocument();
    return pojo;
}
 
开发者ID:egopulse,项目名称:java-code-gen,代码行数:26,代码来源:TestBeanCodec.java

示例13: read

import org.bson.BsonType; //导入依赖的package包/类
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,代码行数:17,代码来源:EnumCodec.java

示例14: readValue

import org.bson.BsonType; //导入依赖的package包/类
@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,代码行数:21,代码来源:DefaultReader.java

示例15: decode

import org.bson.BsonType; //导入依赖的package包/类
/**
 * {@inhericDoc}
 */
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	T instance = instantiate();
	reader.readStartDocument();
	while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
		String fieldName = reader.readName();
		BsoneeBaseSetter<T> bsoneeBaseSetter = settersByName.get(fieldName);
		if (bsoneeBaseSetter != null) {
			bsoneeBaseSetter.set(instance, reader, decoderContext);
		} else {
			// TODO Check options whether to throw an exception or not. By default we skip it :)
			logger.warn("No setter for " + fieldName);
			reader.skipValue();
		}
	}
	reader.readEndDocument();
	return instance;
}
 
开发者ID:guicamest,项目名称:bsoneer,代码行数:22,代码来源:BaseBsoneerCodec.java


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