use of com.mongodb.DBObject in project morphia by mongodb.
the class Converters method toDBObject.
/**
* Converts an entity to a DBObject
*
* @param containingObject The object to convert
* @param mf the MappedField to extract
* @param dbObj the DBObject to populate
* @param opts the options to apply
*/
public void toDBObject(final Object containingObject, final MappedField mf, final DBObject dbObj, final MapperOptions opts) {
final Object fieldValue = mf.getFieldValue(containingObject);
final TypeConverter enc = getEncoder(fieldValue, mf);
final Object encoded = enc.encode(fieldValue, mf);
if (encoded != null || opts.isStoreNulls()) {
dbObj.put(mf.getNameToStore(), encoded);
}
}
use of com.mongodb.DBObject in project mongo-java-driver by mongodb.
the class GridFSTest method testRemoveWhenQueryIsNull.
@Test(expected = IllegalArgumentException.class)
public void testRemoveWhenQueryIsNull() {
DBObject dbObjectQuery = null;
gridFS.remove(dbObjectQuery);
}
use of com.mongodb.DBObject in project mongo-java-driver by mongodb.
the class JSONTest method testBin.
@Test
public void testBin() {
byte[] b = { 'a', 'b', 0, 'd' };
DBObject obj = BasicDBObjectBuilder.start().add("b", b).get();
assertEquals("{ \"b\" : <Binary Data>}", JSON.serialize(obj));
}
use of com.mongodb.DBObject in project mongo-java-driver by mongodb.
the class JSONTest method testNumbers2.
@Test
public void testNumbers2() {
DBObject x = new BasicDBObject("x", 123);
assertEquals(JSON.parse(x.toString()), x);
x = new BasicDBObject("x", 123123123123L);
assertEquals(JSON.parse(x.toString()), x);
x = new BasicDBObject("x", 123123123);
assertEquals(JSON.parse(x.toString()), x);
}
use of com.mongodb.DBObject in project mongo-java-driver by mongodb.
the class JSONTest method testEscape1.
@Test
public void testEscape1() {
String raw = "a\nb";
DBObject x = new BasicDBObject("x", raw);
assertEquals("\"a\\nb\"", JSON.serialize(raw));
assertEquals(x, JSON.parse(x.toString()));
assertEquals(raw, ((DBObject) JSON.parse(x.toString())).get("x"));
x = new BasicDBObject("x", "a\nb\bc\td\re");
assertEquals(x, JSON.parse(x.toString()));
String thingy = "va\"lue";
x = new BasicDBObject("name", thingy);
x = (DBObject) JSON.parse(x.toString());
assertEquals(thingy, x.get("name"));
thingy = "va\\lue";
x = new BasicDBObject("name", thingy);
x = (DBObject) JSON.parse(x.toString());
assertEquals(thingy, x.get("name"));
assertEquals("va/lue", JSON.parse("\"va\\/lue\""));
assertEquals("value", JSON.parse("\"va\\lue\""));
assertEquals("va\\lue", JSON.parse("\"va\\\\lue\""));
escapeChar("\t");
escapeChar("\b");
escapeChar("\n");
escapeChar("\r");
escapeChar("\'");
escapeChar("\"");
escapeChar("\\");
}
Aggregations