Search in sources :

Example 1 with LazyDBCallback

use of com.mongodb.LazyDBCallback in project immutables by immutables.

the class BsonEncoding method unwrapJsonable.

public static DBObject unwrapJsonable(String json) {
    try {
        JsonParser parser = JSON_FACTORY.createParser(json);
        parser.nextToken();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        BsonGenerator generator = BSON_FACTORY.createGenerator(outputStream);
        generator.copyCurrentStructure(parser);
        generator.close();
        parser.close();
        byte[] data = outputStream.toByteArray();
        return (DBObject) new LazyDBCallback(null).createObject(data, 0);
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
}
Also used : BsonGenerator(de.undercouch.bson4jackson.BsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) LazyDBCallback(com.mongodb.LazyDBCallback) DBObject(com.mongodb.DBObject) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)1 DBObject (com.mongodb.DBObject)1 LazyDBCallback (com.mongodb.LazyDBCallback)1 BsonGenerator (de.undercouch.bson4jackson.BsonGenerator)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1