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 6622101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:21:46+00:00 2026-05-25T21:21:46+00:00

I find using JAXB together with Guice possible, but challenging: Both libraries fight for

  • 0

I find using JAXB together with Guice possible, but challenging: Both libraries “fight” for control over object creation, you have to be careful to avoid cyclic dependencies, and it can get messy with all the JAXB Adapters and Guice Providers and stuff. My questions are:

  • How do you deal with this configuration? What general strategies / rules of thumb can be applied?
  • Can you point me to a good tutorial or well written sample code?
  • How to visualize the dependencies (including the Adapters and Providers)?
  • 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-25T21:21:46+00:00Added an answer on May 25, 2026 at 9:21 pm

    For some sample code, some example work was done here: http://jersey.576304.n2.nabble.com/Injecting-JAXBContextProvider-Contextprovider-lt-JAXBContext-gt-with-Guice-td5183058.html

    At the line that says “Wrong?”, put in the recommended line.

    I looks like this:

    @Provider 
    public class JAXBContextResolver implements ContextResolver<JAXBContext> { 
    
        private JAXBContext context; 
        private Class[] types = { UserBasic.class, UserBasicInformation.class }; 
    
        public JAXBContextResolver() throws Exception { 
             this.context = 
           new JSONJAXBContext( 
             JSONConfiguration.natural().build(), types); 
         } 
    
        public JAXBContext getContext(Class<?> objectType) { 
            /* 
            for (Class type : types) { 
                if (type == objectType) { 
                    return context; 
                } 
            } // There should be some kind of exception for the wrong type.
            */ 
            return context; 
        } 
    } 
    
    //My resource method: 
    
        @GET 
        @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 
        public JAXBElement<UserBasic> get(@QueryParam("userName") String userName) { 
            ObjectFactory ob = new ObjectFactory(); 
            UserDTO dto = getUserService().getByUsername(userName); 
            if(dto==null) throw new NotFoundException(); 
            UserBasic ub = new UserBasic(); 
            ub.setId(dto.getId()); 
            ub.setEmailAddress(dto.getEmailAddress()); 
            ub.setName(dto.getName()); 
            ub.setPhoneNumber(dto.getPhoneNumber()); 
            return ob.createUserBasic(ub); 
        } 
    
    //My Guice configuration module: 
    
    public class MyServletModule extends ServletModule { 
    
    
        public static Module[] getRequiredModules() { 
            return new Module[] { 
                    new MyServletModule(), 
                    new ServiceModule(), 
                    new CaptchaModule() 
             }; 
        } 
    
    
        @Override 
        protected void configureServlets() { 
            bind(UserHttpResource.class); 
            bind(JAXBContextResolver.class);
            serve("/*").with(GuiceContainer.class); 
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using .Find to look for a string, but the cells I want
I am trying to get friend birthday list. But how to find using my
All I can find using fopen() and fwrite() in C is to delete all
I have a string with markup in it which I need to find using
I find myself using Resharper's convert to auto property refactoring a lot to remove
I find myself using this method a ton to perform actions based on a
I'm using find for a task and I noticed that when I do something
I find myself using the current pattern quite often in my code nowadays var
I find myself using hash arguments to constructors quite a bit, especially when writing
I often find myself using Integers to represent values in different spaces. For example...

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.