Browse Source

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.
pull/210/merge
Oliver Gierke 12 years ago
parent
commit
07f7247707
  1. 2
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java
  2. 11
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/UpdateTests.java

2
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java

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

11
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/UpdateTests.java

@ -21,6 +21,7 @@ import static org.junit.Assert.*; @@ -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 { @@ -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()));
}
}

Loading…
Cancel
Save