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.
1.5.x
Oliver Gierke 12 years ago
parent
commit
cc785ecf4f
  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

@ -372,7 +372,7 @@ public class Update { @@ -372,7 +372,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;
/**
@ -342,4 +343,14 @@ public class UpdateTests { @@ -342,4 +343,14 @@ public class UpdateTests {
+ "\"$push\" : { \"authors\" : { \"name\" : \"Sven\"}} " //
+ ", \"$pop\" : { \"authors\" : -1}}")); //
}
/**
* @see DATAMONGO-1002
*/
@Test
public void toStringWorksForUpdateWithComplexObject() {
Update update = new Update().addToSet("key", new DateTime());
assertThat(update.toString(), is(notNullValue()));
}
}

Loading…
Cancel
Save