users@jersey.java.net

[Jersey] MIgrating from Jersey 1.x to 2.18

From: Jean-Sebastien Vachon <jean-sebastien.vachon_at_wantedanalytics.com>
Date: Fri, 26 Jun 2015 13:08:27 +0000

Hi All,


I'm migrating our application which uses Jersey 1.x to the latest version of Jersey 2.18. So far everything seems to be working fine but there is one little thing that I could not find how to do...


in the past, we used to implement our own ContextResolver on a Marshaller in order to customize some aspect of the JSON response depending on our user/client preference regarding how number values in the JSON response will be represented. (They could be either numbers or strings). We were doing this by selecting the proper JSONJAXBContext depending on the user's preference.


the two contexts were defined has...


m_DefaultContext = new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false).build(), m_ClazzTypes);



m_NumberAsStringContext = new JSONJAXBContext(JSONConfiguration.natural().writeNumberAsString().rootUnwrapping(false).build(), m_ClazzTypes);

Now, by switching to MOXY to handle how our POJOs are serialized to JSON, I seem to loose the "writeNumberAsString" option. Is there anyway to do this with MOXY?

I switched from implementing a ContextResolver<Marshaller> to a ContextResolver<MoxyJsonConfig> but could not find anything related.

Thanks for your help and time.