DATAMONGO-1002 - Update.toString() now uses SerializationUtils.

A simple call of toString() on a DBObject might result in an exception if the DBObject contains objects that are non-native MongoDB types (i.e. types that need to be converted prior to persistence).

We now use SerializationUtils.serializeToJsonSafely(…) to avoid exceptions.
This commit is contained in:
Oliver Gierke
2014-07-23 12:28:37 +02:00
parent f669711670
commit 07f7247707
2 changed files with 12 additions and 1 deletions

View File

@@ -400,7 +400,7 @@ public class Update {
*/
@Override
public String toString() {
return getUpdateObject().toString();
return SerializationUtils.serializeToJsonSafely(getUpdateObject());
}
/**

View File

@@ -21,6 +21,7 @@ import static org.junit.Assert.*;
import java.util.Collections;
import java.util.Map;
import org.joda.time.DateTime;
import org.junit.Test;
import com.mongodb.BasicDBObject;
@@ -409,4 +410,14 @@ public class UpdateTests {
equalTo(new BasicDBObjectBuilder().add("$currentDate",
new BasicDBObject("foo", true).append("bar", new BasicDBObject("$type", "timestamp"))).get()));
}
/**
* @see DATAMONGO-1002
*/
@Test
public void toStringWorksForUpdateWithComplexObject() {
Update update = new Update().addToSet("key", new DateTime());
assertThat(update.toString(), is(notNullValue()));
}
}