I'm currently looking for a simply way to use Gson instead of Jackson as Provider. Currently I create the Json manually with Gson like this:
Gson gson = new Gson();
String s = gson.toJson(object);
and return it as Response with the specific status message - but that can't be the best solution also with Jackson I simply would can add the object itself.
Looking for a good example which works also for Jersey 1.x - because I want to move also some old project's to it.
I already tried this: http://eclipsesource.com/blogs/2012/11/02/integrating-gson-into-a-jax-rs-based-application/ but couldn't get it to work.
Any help appreciated.
I created this running example on Github https://github.com/DominikAngerer/java-GsonJerseyProvider
It has an improved implementation of the GsonJerseyProvider you found yourself - but also with the web.xml configuration part, because you also need to tell jersey to use your provider.
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.dominikangerer.gson.provider.v1.util,
com.dominikangerer.gson.provider.v1.controller
</param-value>
is here the key part - it will scan the controller package and also the util package where the provider was added.
You can also find an answer from me to this here: https://stackoverflow.com/a/26829468/1581725
This provider will work for Jersey 1.x and also for Jersey 2.x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With