title: Playframework, Converting JSON to Model (with Gson), saving model fails
body: <p>I'am trying to convert a JSON string into my model class. I'am using morphia within the play framework. </p>
  
  <p>Here are the relevant lines of code:</p>
  
  <pre><code>public static void add(JsonObject body) {
      System.out.println(body); // -&gt; {"title":"test2","url":"http://www.gmx.de","description":"eine beschreibung für das lesezeichen","tags":["tag1","tag2","tag3","tag5","tag0209135913598"],"is_private":true}
      Gson gson = new Gson();
      Bookmark bookmark = gson.fromJson(body, Bookmark.class);
      System.out.println(bookmark.getClass().getName()); // -&gt; models.Bookmark    
      bookmark.save(); 
  </code></pre>
  
  <p>But I think that I'am doing something wrong, because this code throws the following exception:</p>
  
  <pre><code>Execution exception (In /app/controllers/Bookmarks.java around line 40)
  IllegalArgumentException occured : can't serialize class java.lang.Object
  
  play.exceptions.JavaExecutionException: can't serialize class java.lang.Object
      at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
      at Invocation.HTTP Request(Play!)
  Caused by: java.lang.IllegalArgumentException: can't serialize class java.lang.Object
      at org.bson.BSONEncoder._putObjectField(BSONEncoder.java:234)
      at org.bson.BSONEncoder.putIterable(BSONEncoder.java:259)
      at org.bson.BSONEncoder._putObjectField(BSONEncoder.java:198)
      at org.bson.BSONEncoder.putObject(BSONEncoder.java:140)
      at org.bson.BSONEncoder.putObject(BSONEncoder.java:86)
      at com.mongodb.OutMessage.putObject(OutMessage.java:190)
      at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:253)
      at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:217)
      at com.mongodb.DBCollection.insert(DBCollection.java:71)
      at com.mongodb.DBCollection.save(DBCollection.java:633)
      at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:764)
      at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:826)
      at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:820)
      at play.modules.morphia.Model.save2(Model.java:705)
      at play.modules.morphia.Model.save(Model.java:692)
      at controllers.Bookmarks.add(Bookmarks.java:40)
      at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
      at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
      at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
      at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
      at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
      ... 1 more
  </code></pre>
  
  <p>It seems like that the following line is throwing this exception:</p>
  
  <pre><code>bookmark.save();
  </code></pre>
  
  <p>Here is the code of the model:</p>
  
  <pre><code>@AutoTimestamp
  @Entity
  public class Bookmark extends Model {
      public String title;
      public String url;
      public String description;
      @Indexed
      public List tags;
      public boolean is_private;
  
      public Bookmark() {}
  
      public Bookmark(String title,
                      String url,
                      String description,
                      List tags,
                      boolean is_private)
      {
          this.title          = title;
          this.url            = url;
          this.description    = description;
          this.tags           = tags;
          this.is_private     = is_private;
      }
  }
  </code></pre>
  
  <p>My question now is how I can fix this, or how I have to create a model instance based on the json input?</p>