title: Alter the json format when serializing to xml or json using JAXB
body: <p>I've got a Java application which uses Accept headers to return XML or Json depending on the client request (to RESTful API's).  We've noticed that although the XML is coming back as we would like the json is a little odd.  Apologies this is a little convoluted now but I have tried to add all the relevant examples and code/annotation.  Any help understanding why the json is returning as it is would be very gratefully received.</p>
  
  <p>So the xml is </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;organisation id="6430D28827FD" href="http://domain.com:80/app/api/organisations/6430D28827FD" created="2014-07-11T11:36:37+01:00"&gt;
  **&lt;links&gt;
      &lt;link href="http://domain.com:80/app/api/orders/E24B07A4" rel="ORDER"/&gt;
      &lt;link href="http://domain.com:80/app/api/orders/FA423645" rel="ORDER"/&gt;
      ...
  &lt;/links&gt;**
  &lt;name&gt;Acme Ltd&lt;/name&gt;
  </code></pre>
  
  <p></p>
  
  <p>when the out put is in json though we get</p>
  
  <pre><code>{
      **"links": {
          "link": [
              {
                  "href": "http://domain.com:80/app/api/orders/E24B07A4",
                  "rel": "ORDER",
                  "otherAttributes": {}
              },
              {
                  "href": "http://domain.com:80/app/api/orders/FA423645",
                  "rel": "ORDER",
                  "otherAttributes": {}
              },
              ...
      ]**
  },
  "id": "6430D28827FD",
  "href": "http://domain.com:80/app/api/organisations/6430D28827FD",
  "created": 1405074997000,
  "name": "Acme Ltd",
  }
  </code></pre>
  
  <p>}</p>
  
  <p>We (think we!) would like to see </p>
  
  <pre><code>    "links": { [
              {
                  "href": "http://domain.com:80/app/api/orders/E24B07A4",
                  "rel": "ORDER",
                  "otherAttributes": {}
              },
              {
                  "href": "http://domain.com:80/app/api/orders/FA423645",
                  "rel": "ORDER",
                  "otherAttributes": {}
              },
              ...
           ]
       }
  </code></pre>
  
  <p>Is there a way to do this (or have we missed the point about how json should be structured?)</p>
  
  <p>The code is as follows</p>
  
  <pre><code>@XmlRootElement(name = "organisations")
  @XmlAccessorType(value = XmlAccessType.PROPERTY)
  public class OrganisationsBean {
      @XmlElement(name = "organisation")
      private List&lt;OrganisationBean&gt; organisations;
  
      private OrganisationsBean() {
      }
  
      public OrganisationsBean(List&lt;OrganisationBean&gt; organisations) {
         this.organisations = organisations;
      }
  
      public List&lt;OrganisationBean&gt; getOrganisations() {
          return organisations;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@XmlType(name = "organisation", propOrder = {"name", …
  public class OrganisationBean extends ResourceBean {
      private String name;
  
      public OrganisationBean() {}
  
      public static OrganisationBean create(String organisationId, String   organisationName, HttpServletRequest request) {
          OrganisationBean organisationBean = new     OrganisationBean(organisationId);
          organisationBean.setName(organisationName);
  …
  
          return organisationBean;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class Organisation {
      private String id;
      private String name;
      private List&lt;OrderSummary&gt; orderSummaries;
      …
  
      public Organisation(String id, String name) {
          this.id = id;
          this.name = name;
      }
  
      public void setOrderSummaries(List&lt;OrderSummary&gt; orderSummaries) {
          this.orderSummaries = orderSummaries ;
      }
      public List&lt;OrderSummary&gt; getOrderSummaries() {
          return orderSummaries ;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "links", propOrder = {"link"})
  public class Links {
      protected List&lt;Link&gt; link;
  
      public List&lt;Link&gt; getLink() {
          if (link == null) {
              link = new ArrayList&lt;Link&gt;();
          }
          return this.link;
      }
  }
  </code></pre>