Parse json array of different object types
<p>I am trying to send an array of different types from Javascript to a Java servlet.  </p>

<p>The Javascript code used to generate and send the data is:  </p>

<pre><code>function sendDataOnButtonPress()
{
  var obj1 = {'key_11': "val_11", 'key_12': "val_12"};
  var obj2 = {'key_21': "val_21", 'key_22': "val_22"};
  var myArray = [obj1, obj2];

  var params = {
      data: JSON.stringify(myArray)
  };

  $.post("serv1", $.param(params), function(response) {
    console.log("response = " + response);
  });
}
</code></pre>

<p>The Java code used to process this data is:  </p>

<pre><code>import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;

@WebServlet("/serv1")
public class serv1 extends HttpServlet {
  private static final long serialVersionUID = 1L;

    public serv1() {
        super();
        // TODO Auto-generated constructor stub
    }

  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String data = request.getParameter("data");
    //System.out.println(data);

    ObjectMapper mapper = new ObjectMapper();
    Object[] objs = mapper.readValue(data, Object[].class);
    System.out.println(objs[0]);

    PrintWriter writer1 = response.getWriter();
    String htmlRespone = "Dummy response";
    writer1.println(htmlRespone);

  }

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }

}
</code></pre>

<p>Although the line <code>System.out.println(objs[0]);</code> is correctly outputting the first object of the array, I am not able to figure out how to access the properties of the object:  </p>

<pre><code>System.out.println(objs[0]["key_11"]);
</code></pre>

<p>is not able to compile.</p>

<p>So, my question is how to correctly parse the data sent from javascript inside Java?</p>

<p>I am open to using any json parsing library other than Jackson too.</p>