Search in sources :

Example 1 with EntityWithListsAndArrays

use of org.mongodb.morphia.entities.EntityWithListsAndArrays in project morphia by mongodb.

the class CustomConvertersTest method customerIteratorConverter.

@Test
public void customerIteratorConverter() {
    getMorphia().getMapper().getConverters().addConverter(ListToMapConvert.class);
    getMorphia().getMapper().getOptions().setStoreEmpties(false);
    getMorphia().getMapper().getOptions().setStoreNulls(false);
    getMorphia().map(EntityWithListsAndArrays.class);
    final EntityWithListsAndArrays entity = new EntityWithListsAndArrays();
    entity.setListOfStrings(Arrays.asList("string 1", "string 2", "string 3"));
    getDs().save(entity);
    final DBObject dbObject = getDs().getCollection(EntityWithListsAndArrays.class).findOne();
    Assert.assertFalse(dbObject.get("listOfStrings") instanceof BasicDBList);
    final EntityWithListsAndArrays loaded = getDs().find(EntityWithListsAndArrays.class).get();
    Assert.assertEquals(entity.getListOfStrings(), loaded.getListOfStrings());
}
Also used : BasicDBList(com.mongodb.BasicDBList) EntityWithListsAndArrays(org.mongodb.morphia.entities.EntityWithListsAndArrays) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Aggregations

BasicDBList (com.mongodb.BasicDBList)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 Test (org.junit.Test)1 EntityWithListsAndArrays (org.mongodb.morphia.entities.EntityWithListsAndArrays)1