title: Gson serialize a list of polymorphic objects
body: <p>I'm trying to serialize/deserialize an object, that involves polymorphism, into JSON using Gson.</p>
  
  <p>This is my code for serializing:</p>
  
  <pre><code>ObixBaseObj lobbyObj = new ObixBaseObj();
  lobbyObj.setIs("obix:Lobby");
  
  ObixOp batchOp = new ObixOp();
  batchOp.setName("batch");
  batchOp.setIn("obix:BatchIn");
  batchOp.setOut("obix:BatchOut");
  
  lobbyObj.addChild(batchOp);
  
  Gson gson = new Gson();
  System.out.println(gson.toJson(lobbyObj));
  </code></pre>
  
  <p>Here's the result:</p>
  
  <pre><code> {"obix":"obj","is":"obix:Lobby","children":[{"obix":"op","name":"batch"}]}
  </code></pre>
  
  <p>The serialization mostly works, except its missing the contents of inherited members (In particular <code>obix:BatchIn</code> and <code>obixBatchout</code> strings are missing).
  Here's my base class:</p>
  
  <pre><code>public class ObixBaseObj  {
      protected String obix;
      private String display;
      private String displayName;
      private ArrayList&lt;ObixBaseObj&gt; children;
  
      public ObixBaseObj()
      {
          obix = "obj";
      }
  
      public void setName(String name) {
          this.name = name;
      }
          ...
  }
  </code></pre>
  
  <p>Here's what my inherited class (ObixOp) looks like:</p>
  
  <pre><code>public class ObixOp extends ObixBaseObj {
      private String in;
      private String out;
  
      public ObixOp() {
          obix = "op";
      }
      public ObixOp(String in, String out) {
          obix = "op";
          this.in = in;
          this.out = out;
      }
      public String getIn() {
          return in;
      }
      public void setIn(String in) {
          this.in = in;
      }
      public String getOut() {
          return out;
      }
      public void setOut(String out) {
          this.out = out;
      }
  }
  </code></pre>
  
  <p>I realize I could use an adapter for this, but the problem is that I'm serializing a collection of base class type <code>ObixBaseObj</code>. There are about 25 classes that inherits from this. How can I make this work elegantly?</p>