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 41fe1809da
commit cc785ecf4f
2 changed files with 12 additions and 1 deletions

View File

@@ -372,7 +372,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;
/**
@@ -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()));
}
}