title: Jersey. How to generate json and xml output depending on url param
body: <p>Here is a <code>Jersey</code> service:</p>
  
  <pre><code>@GET
  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
  public Response service(@QueryParam("format") String format) {
  
    if (format.equals("json")) {...}
  
    return response;
  
  }
  </code></pre>
  
  <p>I want to generate <code>XML</code> or <code>JSON</code> response back depending on <strong>url param</strong> "format".</p>
  
  <p>My <strong>response</strong> instance is forming by <code>jaxb2</code></p>
  
  <p>I know I may get <code>xml</code> or <code>json</code> response back if on my Java client / functional test by using this code:</p>
  
  <pre><code>String content = service.path("").queryParam("myparam", "myvalue").accept(MediaType.APPLICATION_XML).get(String.class);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>String content = service.path("").queryParam("myparam", "myvalue").accept(MediaType.APPLICATION_JSON).get(String.class);
  </code></pre>
  
  <p>But I need to do it depending on url param.</p>