v2.1.1: java.lang.RuntimeException: json can't serialize type : class org.springframework.data.mongodb.core.query.Update$Modifiers
Opened this issue · 0 comments
JamesDunne commented
Using spring-data-mongodb library talking to Fongo, this example pseudocode
DBCollection dbCollection = ...;
Query query = new Query()...;
Update update = new Update().push("...").sort(...).each(...);
dbCollection.update(query.getQueryObject(), update.getUpdateObject());
throws an exception in the debug logging code trying to format as a String the DBObject
created from Update.getUpdateObject()
.
This exception is thrown from FongoDBCollection.update()
when LOG.isDebugEnabled()
is true:
if (LOG.isDebugEnabled()) {
LOG.debug("update(" + q + ", " + o + ", " + upsert + ", " + multi + ")");
}
Full stack trace:
java.lang.RuntimeException: json can't serialize type : class org.springframework.data.mongodb.core.query.Update$Modifiers
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:328)
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:82)
at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:328)
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:82)
at com.mongodb.util.JSON.serialize(JSON.java:53)
at com.mongodb.util.JSON.serialize(JSON.java:39)
at com.mongodb.BasicDBObject.toString(BasicDBObject.java:196)
at java.lang.String.valueOf(String.java:2994)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at com.mongodb.FongoDBCollection.update(FongoDBCollection.java:281)
at com.mongodb.DBCollection.update(DBCollection.java:441)
at com.mongodb.DBCollection.update(DBCollection.java:505)
at com.mongodb.DBCollection.update(DBCollection.java:520)
at my user code that calls update()
Suggested fix is to make a try/catch wrapper around each implied toString()
call in the logging code to make sure that progress continues regardless of incidental formatting exceptions in debug code.