@Converter public static BasicDBObject fromInputStreamToDBObject(InputStream is, Exchange exchange) { BasicDBObject answer = null; try { byte[] input = IOConverter.toBytes(is); if (isBson(input)) { BSONCallback callback = new JSONCallback(); new BasicBSONDecoder().decode(input, callback); answer = (BasicDBObject) callback.get(); } else { answer = (BasicDBObject) JSON.parse(IOConverter.toString(input, exchange)); } } catch (Exception e) { LOG.warn("String -> DBObject conversion selected, but the following exception occurred. Returning null.", e); } finally { // we need to make sure to close the input stream IOHelper.close(is, "InputStream", LOG); } return answer; }
/** * Create a new parser. */ public JSONParser(String s, BSONCallback callback) { this.s = s; _callback = (callback == null) ? new JSONCallback() : callback; }