use of org.bson.BsonInvalidOperationException in project iaf by ibissource.
the class StrictJsonDocumentWriter method writeStartObject.
@Override
public void writeStartObject() {
if (state != State.INITIAL && state != State.VALUE) {
throw new BsonInvalidOperationException("Invalid state " + state);
}
try {
INodeBuilder nodeBuilder = context.contextType == JsonContextType.ARRAY ? ((IArrayBuilder) stack.peek()).addElement() : (INodeBuilder) stack.peek();
stack.push((nodeBuilder).startObject());
} catch (SAXException e) {
throwBSONException(e);
}
context = new StrictJsonContext(context, JsonContextType.DOCUMENT, settings.getIndentCharacters());
state = State.NAME;
}
use of org.bson.BsonInvalidOperationException in project mongo-java-driver by mongodb.
the class NumberCodecHelper method decodeLong.
static long decodeLong(final BsonReader reader) {
long longValue;
BsonType bsonType = reader.getCurrentBsonType();
switch(bsonType) {
case INT32:
longValue = reader.readInt32();
break;
case INT64:
longValue = reader.readInt64();
break;
case DOUBLE:
double doubleValue = reader.readDouble();
longValue = (long) doubleValue;
if (doubleValue != (double) longValue) {
throw invalidConversion(Long.class, doubleValue);
}
break;
case DECIMAL128:
Decimal128 decimal128 = reader.readDecimal128();
longValue = decimal128.longValue();
if (!decimal128.equals(new Decimal128(longValue))) {
throw invalidConversion(Long.class, decimal128);
}
break;
default:
throw new BsonInvalidOperationException(format("Invalid numeric type, found: %s", bsonType));
}
return longValue;
}
Aggregations