title: how to serialize class?
body: <p>When I insert a List into mongodb, there is a problem:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: can't serialize class mongodb.Person
      at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:234)
      at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:259)
      at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:198)
      at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:140)
      at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86)
      at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27)
      at com.mongodb.OutMessage.putObject(OutMessage.java:142)
      at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:252)
      at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:211)
      at com.mongodb.DBCollection.insert(DBCollection.java:57)
      at com.mongodb.DBCollection.insert(DBCollection.java:87)
      at com.mongodb.DBCollection.save(DBCollection.java:716)
      at com.mongodb.DBCollection.save(DBCollection.java:691)
      at mongodb.MongoDB.main(MongoDB.java:45)
  </code></pre>
  
  <p>the class Person is defined as follows:</p>
  
  <pre><code>class Person{
      private String name;
      public Person(String name){
          this.name = name;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>The program is :</p>
  
  <pre><code>        DBCollection coll = db.getCollection("test");
          DBObject record = new BasicDBObject();
          List&lt;Person&gt; persons= new ArrayList&lt;Person&gt;();
          persons.add(new Person("Jack"));
          record.put("person", persons);
          coll.save(record);
  </code></pre>
  
  <p>I can't find the answer from google, so please help me.</p>