Java Code Examples for org.bson.BsonType#ARRAY

The following examples show how to use org.bson.BsonType#ARRAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJsonCodec.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example 2
Source File: ArrayCodec.java    From morphia with Apache License 2.0 6 votes vote down vote up
@Override
public Object[] decode(final BsonReader reader, final DecoderContext decoderContext) {
    List<Object> list = new ArrayList<>();
    if (reader.getCurrentBsonType() == BsonType.ARRAY) {
        reader.readStartArray();

        while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
            list.add(readValue(reader, decoderContext));
        }

        reader.readEndArray();
    } else {
        list.add(readValue(reader, decoderContext));
    }

    return list.toArray();
}
 
Example 3
Source File: BsonReaderWrapper.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
public List<?> startReadList(String field) {
    BsonType currentType = reader.getCurrentBsonType();
    if (currentType == BsonType.NULL) {
        reader.readNull();
        return null;
    }
    if (currentType != BsonType.ARRAY) {
        logger.warn("unexpected field type, field={}, type={}", field, currentType);
        reader.skipValue();
        return null;
    }
    return new ArrayList<>();
}
 
Example 4
Source File: DocumentReader.java    From morphia with Apache License 2.0 5 votes vote down vote up
BsonType getBsonType(final Object o) {
    BsonType bsonType = TYPE_MAP.get(o.getClass());
    if (bsonType == null) {
        if (o instanceof List) {
            bsonType = BsonType.ARRAY;
        } else {
            throw new IllegalStateException(Sofia.unknownBsonType(o.getClass()));
        }
    }
    return bsonType;
}