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


Java BsonReader.readString方法代码示例

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


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

示例1: decode

import org.bson.BsonReader; //导入方法依赖的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

示例2: decode

import org.bson.BsonReader; //导入方法依赖的package包/类
@Override
public final BigInteger decode(final BsonReader reader, final DecoderContext decoderContext) {
	return new BigInteger(reader.readString());
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:5,代码来源:JsonBson.java

示例3: decode

import org.bson.BsonReader; //导入方法依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
    if (reader.getCurrentBsonType() == BsonType.NULL) {
        reader.readNull();
        return null;
    }

    String discriminator = null;
    reader.mark();
    reader.readStartDocument();
    PolymorphicCodec<T> codec = null;
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        String fieldName = reader.readName();
        if (allDiscriminatorKeys.contains(fieldName)) {
            discriminator = reader.readString();
            codec = getCodecForDiscriminator(discriminator);
            if (codec != null) {
                //now check that the codec found actually has the correct
                String discriminatorKeyForClass = discriminatorKeys.get(codec.getEncoderClass());
                if (fieldName.equals(discriminatorKeyForClass)) {
                    break;
                } else {
                    discriminator = null;
                    codec = null;
                    LOGGER.warn("Confusing. Skipping discriminator {} encoded in discriminator key {} since the " +
                                    "destination class is declaring a different discriminator key {}.",
                            discriminator, fieldName, discriminatorKeyForClass);
                }
            }
        } else {
            reader.skipValue();
        }
    }

    reader.reset();

    // try fallback and legacy handling
    if (codec == null) {
        if (discriminator != null) {
            LOGGER.warn("At least one valid discriminator {} was found in database, but no matching codec found at all.", discriminator);
            reader.skipValue();
            return null; // todo: when switching to mongo db 3.6 an exception should be thrown instead of returning null
        }
        LOGGER.debug("No discriminator found in db for entity. Trying fallback. Fallback is {}", fallBackCodec);
        codec = fallBackCodec;
        if (codec == null) {
            LOGGER.debug("FallbackCodec is null. Still no matching codec found for discriminator {} within discriminatorToCodec {}", discriminator, discriminatorToCodec);
            if (classToCodec.values().size() == 1) {
                codec = classToCodec.values().iterator().next();
                LOGGER.debug("Found single possible codec {} for type {}", codec, getEncoderClass());
            }
            else {
                LOGGER.warn("Legacy handling to resolve entities in db without discriminator failed as there are (now?) more than one codecs available {}. One option is to use @DiscriminatrFallback at the legacy class or to add discriminators to the entities within the database. For now, skipping value.", classToCodec);
                // TODO is skipping the right way to handle this? This might lead to lost data if a read object is rewritten to the database again...
                reader.skipValue();
                return null;// todo: when switching to mongo db 3.6 an exception should be thrown instead of returning null
            }
        }
    }


    return decodeWithType(reader, decoderContext, codec);
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:64,代码来源:PolymorphicReflectionCodec.java

示例4: decode

import org.bson.BsonReader; //导入方法依赖的package包/类
@Override
public String decode(BsonReader bsonReader) {
    return bsonReader.readString();
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:5,代码来源:BsonStringConverter.java


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