title: How to post json object from ajax to java class without without servlet but with JAX-RS?
body: <p>I am new to <code>JAX-RS</code>, I am trying to learn new things about it. I am stuck with one issue regarding, creating a <code>JSON</code> object in <code>Java Script</code>, posting it through <code>ajax</code> to a <code>Java</code> class using <code>JAX-RS</code> and <code>annotations</code> and creating a <code>JSON</code> file out of it. I am creating a <code>Maven</code> project for it. Can anyone please suggest me any tutorial for this. I am trying to implement it from past 1 week but unable to do anything.  </p>
  
  <p>Any suggestions appreciated.
  My <code>POST annotation</code> in <code>Java</code> is:</p>
  
  <pre><code>@POST
  @Path("/post")
  @Consumes(MediaType.APPLICATION_JSON) 
  @Produces(MediaType.APPLICATION_JSON)
  public void post(Message obj){
  System.out.println("in post");
  String v_id = obj.getID();
  String v_email = obj.getEmail();
  String v_checkedornot =  obj.getCheckedOrNot();
  System.out.println("id " + v_id +" email " + v_email + " checkedornot " + v_checkedornot);
  }
  </code></pre>
  
  <p>And my <code>AJAX</code> <code>POST</code> is:</p>
  
  <pre><code>var passingObject = {
          ID : '123456',
          userEmail : 'a.a@a',
          ApproverFlag : 'true'
      }
  
  var passobj = JSON.stringify(passingObject);
      $.ajax({
      url: './webapi/messages/post',
      type: 'POST',
      contentType:"application/json",
      data: passobj,
      dataType:'json',
      success:function(data){
          alert(JSON.stringify(data));
      }
  },'json');
  </code></pre>