title: How does JAXB to JSON (and vice versa) work using Jersey?
body: <p>I have successfully implemented a restful service that works with my own client. Now, I wish to make it a service that other clients can also interact with it. In this way, I come to the following questions: (snapshots of my code comes after my questions, the system works fine with my code)</p>
  
  <p>1- How does the data being transmitted between server and client look like? Consider that I haven't used any other JAXB annotations (such as @XMLElement). Is there a way that I can see the produced JSON?</p>
  
  <p>2- JAXB is supposed to be 'Java Architecture for XML Binding' , so, is it sending the data as an XML or JSON (considering that I have specified the request type to be json)? Or, does it convert the object to XML and then to JSON in the client, and in the server, does it get JSON and convert it to XML and then to the Java object?</p>
  
  <p>3- I am using JAXB in my client, but my server is supposed to get a json request. Does it mean that any other client if it produces a json with 'key' and 'value' pairs can interact with my server? Or, is it forcing every client to use JAXB (considering that my method in server has input arguments of the specific object JAXBBean)? Unfortunately, I currently don't know how to create and send a json in Java without using JAXB! So, I couldn't test this question before asking.. I'm going to learn it later.</p>
  
  <p><strong>Parts of my code:</strong></p>
  
  <p>I have used Jersey to implement my restful service. In the client side, I send a post message with a list of JAXB objects to the server. Each JAXB object is an instance of a bean annotated like this:</p>
  
  <pre><code>@XmlRootElement
  public class JAXBBean {
  
  String key;
  String val;
  
  //setters and getters (with no annotation) come here
  ...
  }
  </code></pre>
  
  <p>And I send the List to the server by using:</p>
  
  <pre><code>String response = (String) publishWR.type("application/json").post(String.class, new GenericEntity&lt;List&lt;JAXBBean&gt;&gt; (reqArr){});
  // publishWR is of type: com.sun.jersey.api.client.WebResource
  // reArr is of type: List&lt;JAXBBean&gt;
  </code></pre>
  
  <p>In server side, I have a method that answers to post requests on this web-resource which is written like this:</p>
  
  <pre><code>@POST 
  @Consumes("application/json")    
  public String postAnnotation(List&lt;JAXBBean&gt; requestArr){
      String anno = "";
      String user = "";
      ...
  
      for(int i = 0 ; i &lt; requestArr.size() ; i++ ){
              if( requestArr.get(i).getKey().equals("annotation") )
                  anno = requestArr.get(i).getVal();
              else if( requestArr.get(i).getKey().equals("username") )
                  user = requestArr.get(i).getVal();
              ...
      }
      ...
  }
  </code></pre>
  
  <p>Thank you!</p>