protected void writeNumber(String name, Number value) {
        if (value instanceof Integer || value instanceof Short || value instanceof Byte || value instanceof AtomicInteger) {
            writeFieldSpec(BSON.INT, name);
            output.writeInt(value.intValue());
        } else if (value instanceof Long || value instanceof AtomicLong) {
            writeFieldSpec(BSON.LONG, name);
            output.writeLong(value.longValue());
        } else if (value instanceof Double || value instanceof Float) {
            writeFieldSpec(BSON.DOUBLE, name);
            output.writeDouble(value.doubleValue());
        } else {
            throw new BSONException("can not serialize object: " + value.getClass().getName());
        }
    }