title: How to use multiple JSON providers with CXF, Spring and Jackson
body: <p><strong>Requirement</strong>
  I am building a REST API. It has two REST calls. The call /format to output formatted JSON based on the parameters provided. The call /raw with same parameters should output JSON with raw values (without the formatting). The formatting here would be locale specific like date changes, displaying the correct currency, decimal formatting, time formatting etc for the values. </p>
  
  <p><strong>Tools</strong>
  Java, Tomcat, Spring, Apache CXF, JAX-RS and Jackson. </p>
  
  <p><strong>Implementation</strong>
  REST service is setup and works fine. No problems there. I have written seperate custom serializers in which I provide desired formatting using NumberFormat, DateFormat, DecimalFormat etc. I have extended the SimpleModule from Jackson to register all my custom serializers mentioned above. I am using two separate ObjectMapper (FomatOM and RawOM).FormatOM registers the custom Module for formatted JSON output, RawOM is for raw JSON output as per the requirement. These two objectmappers are registered to two different JacksonJsonProviders and declared as beans in my spring config xml. For /format I use FormatOM with custom serializers, and in /raw I use RawOM.</p>
  
  <p><strong>Problem</strong>
  It doesn't work as I would have expected. I expected that when I make a request through /format call the FormatOM would be used and for /raw RawOM would be used. What is happening is whichever call I make first, subsequent calls are served using the same ObjectMapper. Thus, if the first call is /raw; subsequent calls to /format or /raw render raw JSON output. After a Tomcat restart, if the first call is to /format then subsequent calls to either API calls render formatted JSON output</p>
  
  <p><strong>Questions</strong>
   1. How do you achieve my requirement for rendering formatted + raw JSON
      output?
   2. What's is wrong with my implementation?
   3. Any ideas or suggestions or critiques?
   4. Any other way to have request based mappers?</p>
  
  <p>Thanks</p>