Search in sources :

Example 1 with DefaultDBEncoder

use of com.mongodb.DefaultDBEncoder in project morphia by mongodb.

the class CustomConvertersTest method testFullBSONSerialization.

/**
     * This test shows the full serialization, including bson encoding/decoding.
     */
@Test
public void testFullBSONSerialization() {
    final MyEntity entity = new MyEntity(1L, new ValueObject(2L));
    final DBObject dbObject = getMorphia().toDBObject(entity);
    final byte[] data = new DefaultDBEncoder().encode(dbObject);
    final DBObject decoded = new DefaultDBDecoder().decode(data, (DBCollection) null);
    final MyEntity actual = getMorphia().fromDBObject(getDs(), MyEntity.class, decoded);
    assertEquals(entity, actual);
}
Also used : DefaultDBEncoder(com.mongodb.DefaultDBEncoder) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DefaultDBDecoder(com.mongodb.DefaultDBDecoder) Test(org.junit.Test)

Example 2 with DefaultDBEncoder

use of com.mongodb.DefaultDBEncoder in project camel by apache.

the class MongoDbConversionsTest method testInsertBsonInputStream.

@Test
public void testInsertBsonInputStream() {
    assertEquals(0, testCollection.count());
    DefaultDBEncoder encoder = new DefaultDBEncoder();
    BSONObject bsonObject = new BasicDBObject();
    bsonObject.put("_id", "testInsertBsonString");
    Object result = template.requestBody("direct:insertJsonString", new ByteArrayInputStream(encoder.encode(bsonObject)));
    DBObject b = testCollection.find(new BasicDBObject("_id", "testInsertBsonString")).first();
    assertNotNull("No record with 'testInsertBsonString' _id", b);
}
Also used : DefaultDBEncoder(com.mongodb.DefaultDBEncoder) BasicDBObject(com.mongodb.BasicDBObject) ByteArrayInputStream(java.io.ByteArrayInputStream) BSONObject(org.bson.BSONObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) BSONObject(org.bson.BSONObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 DefaultDBEncoder (com.mongodb.DefaultDBEncoder)2 Test (org.junit.Test)2 DefaultDBDecoder (com.mongodb.DefaultDBDecoder)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BSONObject (org.bson.BSONObject)1