Search in sources :

Example 16 with JsonReader

use of org.bson.json.JsonReader in project mongo-java-driver by mongodb.

the class StringCodecTest method testDecodeOnStringWithObjectIdRep.

@Test(expected = BsonInvalidOperationException.class)
public void testDecodeOnStringWithObjectIdRep() {
    BsonReader reader = new JsonReader("{'name': 'Brian'");
    reader.readStartDocument();
    reader.readName();
    child.decode(reader, decoderContext);
}
Also used : BsonReader(org.bson.BsonReader) JsonReader(org.bson.json.JsonReader) Test(org.junit.Test)

Example 17 with JsonReader

use of org.bson.json.JsonReader in project mongo-java-driver by mongodb.

the class StringCodecTest method testDecodeOnObjectIdWithStringRep.

@Test(expected = BsonInvalidOperationException.class)
public void testDecodeOnObjectIdWithStringRep() {
    BsonReader reader = new JsonReader("{'_id':  ObjectId('5f5a6cc03237b5e06d6b887b'), 'name': 'Brian'}");
    reader.readStartDocument();
    reader.readName();
    parent.decode(reader, decoderContext);
}
Also used : BsonReader(org.bson.BsonReader) JsonReader(org.bson.json.JsonReader) Test(org.junit.Test)

Example 18 with JsonReader

use of org.bson.json.JsonReader in project mongo-java-driver by mongodb.

the class AbstractInsertBenchmark method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    MongoDatabase database = client.getDatabase(DATABASE_NAME);
    collection = database.getCollection(COLLECTION_NAME, clazz);
    database.drop();
    bytes = readAllBytesFromRelativePath(resourcePath);
    fileLength = bytes.length;
    Codec<T> codec = collection.getCodecRegistry().get(clazz);
    document = codec.decode(new JsonReader(new String(bytes, StandardCharsets.UTF_8)), DecoderContext.builder().build());
}
Also used : JsonReader(org.bson.json.JsonReader) MongoDatabase(com.mongodb.client.MongoDatabase)

Aggregations

JsonReader (org.bson.json.JsonReader)18 BsonDocument (org.bson.BsonDocument)5 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)5 BsonReader (org.bson.BsonReader)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 MongoDatabase (com.mongodb.client.MongoDatabase)2 InsertManyOptions (com.mongodb.client.model.InsertManyOptions)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 Converter (org.apache.camel.Converter)2 IOConverter (org.apache.camel.converter.IOConverter)2 BsonArray (org.bson.BsonArray)2 BsonBinaryWriter (org.bson.BsonBinaryWriter)2 ByteBufNIO (org.bson.ByteBufNIO)2 Document (org.bson.Document)2 RawBsonDocument (org.bson.RawBsonDocument)2 RawBsonDocumentCodec (org.bson.codecs.RawBsonDocumentCodec)2 BasicOutputBuffer (org.bson.io.BasicOutputBuffer)2