title: Java JSON serialization - best practice
body: <p>I need to implement JSON serialization for some objects, and I've encountered a problem when it came to integration with generic collections. </p>
  
  <p>All serializable classes implement this interface (JSONObject comes from <a href="http://json.org/java/" rel="noreferrer">this</a> library):</p>
  
  <pre><code>interface JSONSerializable{
      public JSONObject dump() throws JSONException //serializes object
      public void load(JSONObject obj) throws JSONException //deserializes object
  }
  </code></pre>
  
  <p>Code for my collection based on java.util.list looks more or less like this:</p>
  
  <pre><code>class AwesomeList&lt;T extends JSONSerializable&gt; implements JSONSerializable{
      private LinkedList&lt;T&gt; items = new LinkedList&lt;T&gt;();
      ...
      ...
  
      public JSONObject dump() throws JSONException {
          JSONObject result = new JSONObject();
          JSONArray a = new JSONArray();
          for(T i : items){
              a.put(i.dump());
          }
          result.put("items", a);
          return result;
      }
  
      public void load(JSONObject obj) throws JSONException{
          //here is my problem
      }
  }
  </code></pre>
  
  <p>My problem is: When I load AwesomeList from JSONObject, I need to create its elements but it's impossible since java forbids me to write </p>
  
  <pre><code>T newItem = new T();
  newItem.load(obj);
  </code></pre>
  
  <p>How should I modify my approach to this task?</p>