title: How do I i18n JAX-RS (Jersey) JAXB Annotated Responses
body: <p>We are using JAXB Annotations on our model objects that we return from our Web API and we want the data to be localized and other values formatted based on user preferences (i.e. metric vs. statute).  We do this by adding custom adapters to the Marshaller.</p>
  
  <pre><code>Marshaller marshaller = jc.createMarshaller();
  marshaller.setAdapter(NumberPersonalizedXmlAdapter.class,
            new NumberPersonalizedXmlAdapter(locale);
  marshaller.marshal(expected, writer);
  </code></pre>
  
  <p>Attempting the simplest approach I will just get the Locale from the HTTP Request Headers and provide it to the Marshaller in one of the MessageBodyWriter classes.  </p>
  
  <p>I looked at extending the default registered providers like XMLRootElementProvider, but realized they were written as mostly final so I abandoned that approach. There would have been at least 10 classes I needed to extend anyway so that wasn't ideal.</p>
  
  <p>Does anyone know how best to get the marshaller in the MessageBodyWriter set up with customer Adapters for each request? I'm pretty sure it has something to do with <a href="http://NumberFormat%20formatter%20=%20NumberFormat.getNumberInstance%28locale%29;" rel="nofollow">ContextResolver</a>.</p>