Search in sources :

Example 1 with BsonReader

use of org.immutables.mongo.bson4gson.BsonReader in project immutables by immutables.

the class Jsons method asGsonReader.

static JsonReader asGsonReader(BsonDocument bson) {
    BasicOutputBuffer output = new BasicOutputBuffer();
    new BsonDocumentCodec().encode(new BsonBinaryWriter(output), bson, EncoderContext.builder().build());
    return new BsonReader(new BsonBinaryReader(ByteBuffer.wrap(output.toByteArray())));
}
Also used : BsonReader(org.immutables.mongo.bson4gson.BsonReader) BsonBinaryReader(org.bson.BsonBinaryReader) BsonBinaryWriter(org.bson.BsonBinaryWriter) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

Example 2 with BsonReader

use of org.immutables.mongo.bson4gson.BsonReader in project immutables by immutables.

the class Jsons method readerAt.

/**
 * Creates reader for position at {@code value}
 */
static JsonReader readerAt(BsonValue value) throws IOException {
    BsonDocument doc = new BsonDocument("value", value);
    BsonReader reader = new BsonReader(new BsonDocumentReader(doc));
    // advance AFTER value token
    reader.beginObject();
    check(reader.peek()).is(JsonToken.NAME);
    check(reader.nextName()).is("value");
    return reader;
}
Also used : BsonDocument(org.bson.BsonDocument) BsonReader(org.immutables.mongo.bson4gson.BsonReader) BsonDocumentReader(org.bson.BsonDocumentReader)

Aggregations

BsonReader (org.immutables.mongo.bson4gson.BsonReader)2 BsonBinaryReader (org.bson.BsonBinaryReader)1 BsonBinaryWriter (org.bson.BsonBinaryWriter)1 BsonDocument (org.bson.BsonDocument)1 BsonDocumentReader (org.bson.BsonDocumentReader)1 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)1 BasicOutputBuffer (org.bson.io.BasicOutputBuffer)1