Package org.jongo.bson

Examples of org.jongo.bson.BsonDocument.toDBObject()


    @Test
    public void canMarshall() {

        BsonDocument doc = engine.marshall(new Fox("fantastic", "roux"));

        DBObject dbo = doc.toDBObject();
        assertThat(dbo.get("_class")).isEqualTo("org.jongo.model.Fox");
        assertThat(dbo.get("name")).isEqualTo("fantastic");
        assertThat(dbo.get("color")).isEqualTo("roux");
    }
View Full Code Here


        Fox vixen = new Fox("fantastic", "roux");
        vixen.setGender("female");

        BsonDocument doc = custom.marshall(vixen);

        DBObject result = doc.toDBObject();
        assertThat(result.get("gender")).isNull();
        assertThat(result.get("_class")).isEqualTo("org.jongo.model.Fox");
        assertThat(result.get("name")).isEqualTo("fantastic");
        assertThat(result.get("color")).isEqualTo("roux");
    }
View Full Code Here

        Fox vixen = new Fox("fantastic", "roux");
        vixen.setGender("female");

        BsonDocument doc = custom.marshall(vixen);

        DBObject result = doc.toDBObject();
        assertThat(result.get("_class")).isEqualTo("org.jongo.model.Fox");
        assertThat(result.get("name")).isEqualTo("fantastic");
        assertThat(result.get("color")).isEqualTo("roux");
        assertThat(result.get("gender")).isEqualTo("female");
    }
View Full Code Here

        if (parameter instanceof Enum) {
            return marshallPrimitiveWithWrapper(parameter);
        } else {
            BsonDocument document = marshaller.marshall(parameter);
            DBObject dbo = document.toDBObject();

            if (dbo.keySet().isEmpty()) {
                return marshallPrimitiveWithWrapper(parameter);
            } else {
                return dbo;
View Full Code Here

    private Object marshallPrimitiveWithWrapper(Object parameter) {
        final BsonDocument document;

        Map<String, Object> primitiveWrapper = Collections.singletonMap("wrapped", parameter);
        document = marshaller.marshall(primitiveWrapper);
        return document.toDBObject().get("wrapped");
    }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.