title: Convert Spring Mongo Update to JSON String
body: <p>I have an instance of an <code>Update</code> object and I would like to convert it to its String JSON representation so I can use it later.</p>
  
  <p>I created the update object like this:</p>
  
  <pre><code>Update update = new Update();
  update.set("field", new SomeClass());
  update.unset("otherField");
  // etc
  </code></pre>
  
  <p>My initial attempt was:</p>
  
  <pre><code>update.getUpdateObject().toString();
  </code></pre>
  
  <p>This approach worked for most cases but it failed occasionally because it could not serialize an instance of <code>SomeClass</code>. This was the stacktrace:</p>
  
  <pre><code>java.lang.RuntimeException: json can't serialize type : class com.example.SomeClass
  at com.mongodb.util.JSON.serialize(JSON.java:261)
      at com.mongodb.util.JSON.serialize(JSON.java:115)
      at com.mongodb.util.JSON.serialize(JSON.java:161)
      at com.mongodb.util.JSON.serialize(JSON.java:141)
      at com.mongodb.util.JSON.serialize(JSON.java:58)
      at com.mongodb.BasicDBObject.toString(BasicDBObject.java:84)
  </code></pre>
  
  <p>I have available an instance of <code>MongoTemplate</code> and <code>MongoConverter</code> but I am unsure about how to use these classes to do this task.</p>
  
  <p>The question is:</p>
  
  <p>What's the correct way to get the JSON representation of an Update object?</p>
  
  <p>I'm using spring-data-mongodb version 1.1.0.M1. </p>