Search in sources :

Example 1 with JsonObject

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());
}
Also used : JsonObject(org.bson.json.JsonObject) ClusterFixture.isServerlessTest(com.mongodb.ClusterFixture.isServerlessTest) Test(org.junit.Test)

Example 2 with JsonObject

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());
}
Also used : StringWriter(java.io.StringWriter) JsonObject(org.bson.json.JsonObject) JsonWriter(org.bson.json.JsonWriter)

Aggregations

JsonObject (org.bson.json.JsonObject)2 ClusterFixture.isServerlessTest (com.mongodb.ClusterFixture.isServerlessTest)1 StringWriter (java.io.StringWriter)1 JsonWriter (org.bson.json.JsonWriter)1 Test (org.junit.Test)1