Search in sources :

Example 11 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class CommandOperationHelper method executeWrappedCommandProtocolAsync.

static <T> void executeWrappedCommandProtocolAsync(final AsyncWriteBinding binding, final String database, final BsonDocument command, final AsyncConnection connection, final CommandTransformer<BsonDocument, T> transformer, final SingleResultCallback<T> callback) {
    notNull("binding", binding);
    executeWrappedCommandProtocolAsync(database, command, new BsonDocumentCodec(), connection, primary(), transformer, callback);
}
Also used : BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Example 12 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class CommandResultCodecProvider method addCodecs.

private void addCodecs() {
    addCodec(new BsonNullCodec());
    addCodec(new BsonBinaryCodec());
    addCodec(new BsonBooleanCodec());
    addCodec(new BsonDateTimeCodec());
    addCodec(new BsonDBPointerCodec());
    addCodec(new BsonDoubleCodec());
    addCodec(new BsonInt32Codec());
    addCodec(new BsonInt64Codec());
    addCodec(new BsonDecimal128Codec());
    addCodec(new BsonMinKeyCodec());
    addCodec(new BsonMaxKeyCodec());
    addCodec(new BsonJavaScriptCodec());
    addCodec(new BsonObjectIdCodec());
    addCodec(new BsonRegularExpressionCodec());
    addCodec(new BsonStringCodec());
    addCodec(new BsonSymbolCodec());
    addCodec(new BsonTimestampCodec());
    addCodec(new BsonUndefinedCodec());
    addCodec(new BsonJavaScriptWithScopeCodec(new BsonDocumentCodec()));
}
Also used : BsonObjectIdCodec(org.bson.codecs.BsonObjectIdCodec) BsonBooleanCodec(org.bson.codecs.BsonBooleanCodec) BsonSymbolCodec(org.bson.codecs.BsonSymbolCodec) BsonUndefinedCodec(org.bson.codecs.BsonUndefinedCodec) BsonDateTimeCodec(org.bson.codecs.BsonDateTimeCodec) BsonDBPointerCodec(org.bson.codecs.BsonDBPointerCodec) BsonJavaScriptWithScopeCodec(org.bson.codecs.BsonJavaScriptWithScopeCodec) BsonMinKeyCodec(org.bson.codecs.BsonMinKeyCodec) BsonBinaryCodec(org.bson.codecs.BsonBinaryCodec) BsonDoubleCodec(org.bson.codecs.BsonDoubleCodec) BsonInt32Codec(org.bson.codecs.BsonInt32Codec) BsonDecimal128Codec(org.bson.codecs.BsonDecimal128Codec) BsonRegularExpressionCodec(org.bson.codecs.BsonRegularExpressionCodec) BsonStringCodec(org.bson.codecs.BsonStringCodec) BsonInt64Codec(org.bson.codecs.BsonInt64Codec) BsonMaxKeyCodec(org.bson.codecs.BsonMaxKeyCodec) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BsonNullCodec(org.bson.codecs.BsonNullCodec) BsonJavaScriptCodec(org.bson.codecs.BsonJavaScriptCodec) BsonTimestampCodec(org.bson.codecs.BsonTimestampCodec)

Example 13 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class BsonDocumentTest method toJsonShouldRespectDefaultJsonWriterSettings.

@Test
public void toJsonShouldRespectDefaultJsonWriterSettings() {
    StringWriter writer = new StringWriter();
    new BsonDocumentCodec().encode(new JsonWriter(writer), document, EncoderContext.builder().build());
    assertEquals(writer.toString(), document.toJson());
}
Also used : StringWriter(java.io.StringWriter) JsonWriter(org.bson.json.JsonWriter) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) Test(org.junit.Test)

Example 14 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class BsonHelper method toBson.

public static ByteBuffer toBson(final BsonDocument document) {
    BasicOutputBuffer bsonOutput = new BasicOutputBuffer();
    new BsonDocumentCodec().encode(new BsonBinaryWriter(bsonOutput), document, EncoderContext.builder().build());
    return ByteBuffer.wrap(bsonOutput.toByteArray());
}
Also used : BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

Example 15 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class GenericBsonDecimal128Test method encodeToHex.

private String encodeToHex(final BsonDocument decodedDocument) {
    BasicOutputBuffer outputBuffer = new BasicOutputBuffer();
    new BsonDocumentCodec().encode(new BsonBinaryWriter(outputBuffer), decodedDocument, EncoderContext.builder().build());
    return DatatypeConverter.printHexBinary(outputBuffer.toByteArray());
}
Also used : BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

Aggregations

BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)26 BsonDocument (org.bson.BsonDocument)9 BasicOutputBuffer (org.bson.io.BasicOutputBuffer)5 StringWriter (java.io.StringWriter)4 JsonWriter (org.bson.json.JsonWriter)4 ByteBuffer (java.nio.ByteBuffer)3 BsonBinaryReader (org.bson.BsonBinaryReader)3 MongoNamespace (com.mongodb.MongoNamespace)2 WriteConcernResult (com.mongodb.WriteConcernResult)2 BsonBinaryWriter (org.bson.BsonBinaryWriter)2 BsonDocumentWriter (org.bson.BsonDocumentWriter)2 ByteBufferBsonInput (org.bson.io.ByteBufferBsonInput)2 Test (org.junit.Test)2 MongoCursorNotFoundException (com.mongodb.MongoCursorNotFoundException)1 WriteConcernException (com.mongodb.WriteConcernException)1 BulkWriteResult (com.mongodb.bulk.BulkWriteResult)1 WriteCommandResultHelper.getBulkWriteResult (com.mongodb.connection.WriteCommandResultHelper.getBulkWriteResult)1 BsonDocumentWrapper (org.bson.BsonDocumentWrapper)1 ByteBuf (org.bson.ByteBuf)1 ByteBufNIO (org.bson.ByteBufNIO)1