title: How to extract data which is sent from ajax request as a Json Array of objects repetitively in spring-mvc controller?
body: <p>I am sending a set of data as Json Array of objects from ajax function to my spring mvc controller method. ie.</p>
  
  <pre><code>[{"item":"Cheese Lover","size":"960.00","qty":"1"},{"item":"Garlic Bread","size":"390.00","qty":"1"},{"item":"pudding3","size":"420.00","qty":"2"}]
  </code></pre>
  
  <p>I need to extract these data separately as item, size and qty so that I can feed the fields to sql and send the data to database. But I am got stuck here as I have no idea how to do it properly and this is the controller method which I have used so far.</p>
  
  <pre><code> @RequestMapping(value = "/add_package")
      public @ResponseBody
      String addPackage(@ModelAttribute("command") Package newPackage,
                        // @RequestBody PackageContent[] content,
                        HttpServletRequest request){
          PackageContent packageContent = new PackageContent();
          String s=request.getParameter("test");
  
          ObjectMapper objectMapper=new ObjectMapper();
          JSONObject obj= new JSONObject();
  
          try {
              obj=objectMapper.readValue(s, JSONObject.class);
              obj.get(packageContent.getItem());
  
              /*for(PackageContent content1 : s){
                  //System.out.println(content1.getItem());
                  LOGGER.trace("hhh  "+content1.getItem());
              }*/
  
          } catch (Exception e) {
              LOGGER.error("error {}",e);
          }
  
          return obj.toString();}
  </code></pre>
  
  <p>When I log the result in console,in ajax success function it shows only as <code>{}</code>.
  I am doing this on form submit button click and is it wrong to do so? If so
  when and how can I extract these data repetitively in controller so that send them to the sql code?</p>