use of com.mongodb.util.JSONCallback in project camel by apache.
the class MongoDbBasicConverters method fromInputStreamToDBObject.
@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;
}
Aggregations