title: MongoDB + Spring Data Converters with embedded objects
body: <p>I have a write converter as </p>
  
  <pre><code>public class CarConverter implements Converter&lt;Car, DBObject&gt; {
  
  @Override
  public final DBObject convert(final Car car) {
      DBObject dbo = new BasicDBObject();
      dbo.put("_id", car.getId());
      // below line produces error
      dbo.put("wheels", car.getWheels());
      return dbo;
   }
  }
  </code></pre>
  
  <p>and my <strong>Car.java</strong> as </p>
  
  <pre><code>@Document(collection = "car")
  public class Car implements Serializable {
  private static final long serialVersionUID = 6121244806685144430L;
  
  @Id private String id;
  private List&lt;Wheel&gt; wheels;
  
  // getters and setters
  }
  </code></pre>
  
  <p>and my <strong>Wheel.java</strong> as (<em>It is not document , just a bean</em>)</p>
  
  <pre><code>public class Wheel implements Serializable {
  private static final long serialVersionUID = 6121244806685144430L;
  
  private String wheelId;
  private String name;
  
  //getters and setters
  }
  </code></pre>
  
  <p>I got the below error when I try to <strong>save</strong> my <strong>Car</strong> object to mongodb.</p>
  
  <pre><code>SLF4J: Failed toString() invocation on an object of type [com.mongodb.BasicDBObject]
  java.lang.RuntimeException: json can't serialize type : class com.mypackage.Wheel
  at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:77)
  at com.mongodb.util.JSONSerializers$IterableSerializer.serialize(JSONSerializers.java:290)
  at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
  at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:317)
  at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
  at com.mongodb.util.JSON.serialize(JSON.java:55)
  at com.mongodb.util.JSON.serialize(JSON.java:40)
  at com.mongodb.BasicDBObject.toString(BasicDBObject.java:83)
  at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:276)
  at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:248)
  at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:206)
  at org.slf4j.helpers.MessageFormatter.format(MessageFormatter.java:148)
  at org.slf4j.impl.Log4jLoggerAdapter.info(Log4jLoggerAdapter.java:341)
  INFO : org.springframework.data.mongodb.core.mapping.event.LoggingEventListener - onBeforeSave:
  com.mypackage.Car@1e4ec58, [FAILED toString()]
  java.lang.IllegalArgumentException: can't serialize class com.mypackage.Wheel
  at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:284)
  at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:309)
  at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:248)
  at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:185)
  at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:131)
  at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:33)
  at com.mongodb.OutMessage.putObject(OutMessage.java:289)
  at com.mongodb.OutMessage.writeUpdate(OutMessage.java:180)
  at com.mongodb.OutMessage.update(OutMessage.java:60)
  at com.mongodb.DBCollectionImpl.update(DBCollectionImpl.java:275)
  at com.mongodb.DBCollection.update(DBCollection.java:191)
  at com.mongodb.DBCollection.save(DBCollection.java:975)
  at com.mongodb.DBCollection.save(DBCollection.java:934)
  </code></pre>
  
  <p>Please somebody help me , what is the problem ? How can I fix it ?</p>