title: JSON JAX-RS in Java
body: <p>I'm using Jersey for a RESTful web service in Java. I'm consuming them from a PHP client. I have it working fine with JSON as follows:</p>
  
  <p>PHP: (using httpful phar)</p>
  
  <pre><code> $uri="http://localhost:8080/YYYYY/rest/common/json";
      $r = \Httpful\Request::post($uri)
      -&gt;body({"name":"MyName"})-&gt;send();
      return $r;
  </code></pre>
  
  <p>Java RESTful WS:</p>
  
  <pre><code>@POST
  @Path(value="json")
  @Produces(MediaType.TEXT_HTML)
  @Consumes(MediaType.APPLICATION_JSON)
  public String jsonTest(final JaxData data)
  {
      System.out.println(data.toString());
      return "this is the name: "+data.name;
  }
  </code></pre>
  
  <p>Java binding class:</p>
  
  <pre><code>@XmlRootElement
  public class JaxData {
      @XmlElement public String name; 
  }
  </code></pre>
  
  <p>Now what I want to do is to send the following JSON structure:</p>
  
  <pre><code>{
  "title":"MyTitle",
  "names":[
      {
          "name":"nameOne"
      },
      {
          "name":"nameTwo"
      }
  ],
  "city":"MyCity",
  "country": "MyCountry"
      }
  </code></pre>
  
  <p>So as you can see I want to send objects inside objects apart from the primitive types of Java. How can I do this from the Java side? Thank you!</p>