use of org.bson.BsonReader in project mongo-java-driver by mongodb.
the class ProtocolHelper method getNestedFieldValue.
@SuppressWarnings("SameParameterValue")
private static BsonValue getNestedFieldValue(final ResponseBuffers responseBuffers, final String topLevelFieldName, final String nestedFieldName) {
try {
BsonReader bsonReader = createBsonReader(responseBuffers);
bsonReader.readStartDocument();
while (bsonReader.readBsonType() != BsonType.END_OF_DOCUMENT) {
if (bsonReader.readName().equals(topLevelFieldName)) {
return getField(bsonReader, nestedFieldName);
}
bsonReader.skipValue();
}
bsonReader.readEndDocument();
return null;
} finally {
responseBuffers.reset();
}
}
use of org.bson.BsonReader 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);
}
use of org.bson.BsonReader 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);
}
use of org.bson.BsonReader in project morphia by mongodb.
the class DocumentReaderTest method read.
@Test
public void read() {
setup(new Document("key", "value").append("numbers", List.of(1, 2, 3, 4, 5)).append("another", "entry"));
step(BsonReader::readStartDocument);
step(r -> assertEquals(r.getCurrentBsonType(), BsonType.STRING));
step(r -> assertEquals(r.readName(), "key"));
step(r -> assertEquals(r.readString(), "value"));
step(r -> assertEquals(r.readName(), "numbers"));
step(BsonReader::readStartArray);
for (int i = 1; i < 6; i++) {
final int finalI = i;
step(r -> assertEquals(finalI, r.readInt32()));
}
step(BsonReader::readEndArray);
step(r -> assertEquals(r.readName(), "another"));
step(r -> assertEquals(r.readString(), "entry"));
step(BsonReader::readEndDocument);
}
use of org.bson.BsonReader in project morphia by mongodb.
the class DocumentReaderTest method mark.
@Test
public void mark() {
setup(new Document("key", "value").append("nested", "detsen"));
step(BsonReader::readStartDocument);
BsonReaderMark docMark = reader.getMark();
step(r -> assertEquals(r.readName(), "key"));
step(r -> assertEquals(r.readString(), "value"));
docMark.reset();
step(r -> assertEquals(r.readName(), "key"));
step(r -> assertEquals(r.readString(), "value"));
step(r -> assertEquals(r.readName(), "nested"));
step(r -> assertEquals(r.readString(), "detsen"));
step(BsonReader::readEndDocument);
}
Aggregations