Search in sources :

Example 6 with BsonInvalidOperationException

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;
}
Also used : BsonInvalidOperationException(org.bson.BsonInvalidOperationException) INodeBuilder(nl.nn.adapterframework.stream.document.INodeBuilder) SAXException(org.xml.sax.SAXException)

Example 7 with BsonInvalidOperationException

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;
}
Also used : BsonType(org.bson.BsonType) BsonInvalidOperationException(org.bson.BsonInvalidOperationException) Decimal128(org.bson.types.Decimal128)

Aggregations

BsonInvalidOperationException (org.bson.BsonInvalidOperationException)7 BsonType (org.bson.BsonType)3 Decimal128 (org.bson.types.Decimal128)3 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1 INodeBuilder (nl.nn.adapterframework.stream.document.INodeBuilder)1 BsonDocument (org.bson.BsonDocument)1 BsonReaderMark (org.bson.BsonReaderMark)1 Document (org.bson.Document)1 CodecConfigurationException (org.bson.codecs.configuration.CodecConfigurationException)1 JsonParseException (org.bson.json.JsonParseException)1 SAXException (org.xml.sax.SAXException)1