title: Posting JSON array using Ajax and parse in servlet using Gson
body: <p>I am new to Java and stuck with this problem. I'm building an array in JavaScript which looks like this</p>
  
  <pre><code>  var jsonObj = [];
  
    jsonObj.push(
    {
       Effect: "Deny",
       RuleID: "Rule1"
     },
     {
       Effect: "Deny",
       RuleID: "Rule2"
     },
     {
       Effect: "Deny",
       RuleID: "Rule3"
      },....
  
      )
  </code></pre>
  
  <p>After this I am passing this to servlet using Ajax:</p>
  
  <pre><code> jQuery.ajax({ 
      url: "http://localhost:8080/PolicyConsumerServlet/PolicyServlet",  
      dataType: "json",
      type: 'POST',
      data: {jsondata : JSON.stringify(jsonObj)},
  
       contentType: 'application/json',
          mimeType: 'application/json',
          success: function(data) { 
  
              alert('Hi');
          },
      error: function(jqXHR, textStatus, errorThrown) {
          alert("error occurred");
      } 
  });
  </code></pre>
  
  <p>In servlet, in <code>doPost</code> method I have written below code</p>
  
  <pre><code>  StringBuffer jb = new StringBuffer();
    String line = null;
  
    BufferedReader reader = request.getReader();
    RequestMaker.requestProcess();
    while ((line = reader.readLine()) != null)
        jb.append(line);
  
    String jsonstring = jb.toString(); 
    Gson gson = new Gson();
  
    Wrapper[] data = gson.fromJson(jsonstring, Wrapper[].class);
  
    System.out.println(jb);
  </code></pre>
  
  <p>and Wrapper class is </p>
  
  <pre><code>public class Wrapper {
    String Effect;
    String RuleID;
  }
  </code></pre>
  
  <p>But this is throwing exception at below line</p>
  
  <pre><code>    Wrapper [] data = gson.fromJson(jsonstring, Wrapper[].class);
  </code></pre>
  
  <p>What is wrong in parsing this JSON?</p>