title: How to convert List to a JSON Object using GSON?
body: <p>I have a List which I need to convert into JSON Object using GSON. My JSON Object has JSON Array in it. </p>
  
  <pre><code>public class DataResponse {
  
      private List&lt;ClientResponse&gt; apps;
  
      // getters and setters
  
      public static class ClientResponse {
          private double mean;
          private double deviation;
          private int code;
          private String pack;
          private int version;
  
          // getters and setters
      }
  }
  </code></pre>
  
  <p>Below is my code in which I need to convert my List to JSON Object which has JSON Array in it - </p>
  
  <pre><code>public void marshal(Object response) {
  
      List&lt;DataResponse.ClientResponse&gt; clientResponse = ((DataResponse) response).getClientResponse();
  
      // now how do I convert clientResponse list to JSON Object which has JSON Array in it using GSON?
  
      // String jsonObject = ??
  }
  </code></pre>
  
  <p>As of now, I only have two items in List - So I need my JSON Object like this - </p>
  
  <pre><code>{  
     "apps":[  
        {  
           "mean":1.2,
           "deviation":1.3
           "code":100,
           "pack":"hello",
           "version":1
        },
        {  
           "mean":1.5,
           "deviation":1.1
           "code":200,
           "pack":"world",
           "version":2
        }
     ]
  }
  </code></pre>
  
  <p>What is the best way to do this?</p>