use of org.bson.json.JsonObject in project mongo-java-driver by mongodb.
the class MongoCollectionTest method testJsonObjectEncodingAndDecoding.
@Test
public void testJsonObjectEncodingAndDecoding() {
// given
MongoCollection<JsonObject> test = database.getCollection("test", JsonObject.class);
JsonObject json = new JsonObject("{\"_id\": {\"$oid\": \"5f5a5442306e56d34136dbcf\"}, \"hello\": 1}");
test.drop();
// when
test.insertOne(json);
// then
assertEquals(json, test.find().first());
}
use of org.bson.json.JsonObject in project mongo-java-driver by mongodb.
the class JsonObjectCodec method decode.
@Override
public JsonObject decode(final BsonReader reader, final DecoderContext decoderContext) {
StringWriter stringWriter = new StringWriter();
new JsonWriter(stringWriter, writerSettings).pipe(reader);
return new JsonObject(stringWriter.toString());
}
Aggregations