Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7661861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:39:34+00:00 2026-05-31T13:39:34+00:00

With Jersey, I am currently using the Gson library to convert my pojo to

  • 0

With Jersey, I am currently using the Gson library to convert my pojo to json back and forth.
However, I’ve discovered Jackson to be a lot faster so we are switching to this.

I already have a Gson custom Provider and Reader, and will now create (a modified) version for Jackson.

But during development, it would be good if I could swap them but is this possible? Since I mark the json provider with @produces and @consumes I dont think Jersey could resolve which one to use if there were two providers, each with the above annotations for the same type, in this case APPLICATION_JSON.

Is it possible to specify multiple Json providers, and then swap them in some config file (web.xml??) ?

I know if I created a Json Wrapper object I could code to an interface and using spring to swap implementations easily (jackson imp vs gson imp) but this would mean i wouldnt be doing it the Jax RS way. Also, I would be forced to return a String for all the GETs rather than let the providers convert it for me implicitly.

Any thoughts?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:39:35+00:00Added an answer on May 31, 2026 at 1:39 pm

    If you create your own subclass of ResourceConfig (or JAX-RS Application), it has a method named getClasses() – that’s where you have to return set of resource and provider classes that your application uses. Now, seems you are using some of the pre-packaged ResourceConfig – Jersey has ResourceConfig that does class-path scanning (i.e. if you configure that one – or none – since this one is the default) it scans the whole class path for resource classes). There is one that is capable of package scanning – that one scans just the packages you list in your init params of Jersey servlet, etc.

    Actually, the package scanning one may be best for you. Just make sure you put each of your JSON providers in a different package and then configure in web.xml which packages should be scanned for resources and providers. Here is an example of web.xml that configures Jersey to look for resources and providers in com.mycompany.resource and com.mycompany.providers.gson packages:

    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <servlet>
            <servlet-name>Jersey Web Application</servlet-name>
            <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
            <init-param>
                <param-name>com.sun.jersey.config.property.packages</param-name>
                <param-value>com.mycompany.resources,com.mycompany.providers.gson</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>Jersey Web Application</servlet-name>
            <url-pattern>/webresources/*</url-pattern>
        </servlet-mapping>
    </web-app>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Jersey's integrated Jackson processing to transform incoming JSON to a POJO, e.g.:
I am currently developing a RESTful Webservice in Java using the Jersey library. For
Using Jersey and Jackson to create a REST interface, how do I get List
In my Jersey project, I am using MOXy to marshal to/from JSON. One of
I'm currently building a simple REST interface using Jersey with embedded Jetty. Server server
We are currently using a Jersey JAX-RS implementation to handle our REST requests (server-side
I'm developing a web service using REST (Jersey 1.8). Currently I'm using XML to
I'm currently using Jersey as a proxy REST api to call another RESTful web
Im currently working on a grizzly, spring and jersey project and i have encountered:
Using Jersey, I want to be able to have a GET request, that would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.