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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:36:43+00:00 2026-05-24T23:36:43+00:00

I have some @javax.xml.bind.annotation.Xml… annotated classes here intended for a RESt web service. Jersey

  • 0

I have some @javax.xml.bind.annotation.Xml… annotated classes here intended for a RESt web service. Jersey is setup in a spring managed web container and the web service is returning a well formatted xml. We use the maven-enunciate-plugin to document the web service and create the xsd to the returned xml documents. I now would like to use the documentation xsd file as a schemaLocation within the returned xml file so that the xml validation won’t complain about missing definions. How can I get the XML serialisation configured for this?

  • 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-24T23:36:44+00:00Added an answer on May 24, 2026 at 11:36 pm

    If I remember correctly, I had to do a few of things to get namespace identifiers properly written into my generated XML.

    1) Created a JaxbFactory that configs and returns a custom marshaller (and unmarshaller, too, BTW). I’m omitting the getters/and unmarshalling setup below…

    //constructor
    public JaxbFactory() throws Exception {
        context = JAXBContext.newInstance(ResourceDto.class);
    
        // Setup the marshaller
        marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, XmlMetadataConstants.XML_SCHEMA_LOCATION);  // this schema location is used in generating the schema-location property in the xml
    }
    

    2) That factory class isn’t “visible” to Jersey. To make it visible, I create a MarshallerProvider. That looks something like this:

    @Provider
    public class ResourceJaxbMarshallerProvider implements ContextResolver<Marshaller> {
    // injected by Spring
    private ResourceJaxbFactory ResourceJaxbFactory;
    private ResourceStatusJaxbFactory ResourceStatusJaxbFactory;
    
    
    /*
     * ----------------------------------------
     * Setters (for Spring injected properties)
     * ----------------------------------------
     */
    public void setResourceJaxbFactory(ResourceJaxbFactory ResourceJaxbFactory) {
        this.ResourceJaxbFactory = ResourceJaxbFactory;
    }
    
    public void setResourceStatusJaxbFactory(ResourceStatusJaxbFactory ResourceStatusJaxbFactory) {
        this.ResourceStatusJaxbFactory = ResourceStatusJaxbFactory;
    }
    
    /*
     * ------------------------
     * Interface Implementation
     * ------------------------
     */
    public Marshaller getContext(Class<?> type) {
        if (type == ResourceDto.class)
            return ResourceJaxbFactory.getMarshaller();
        else if (type == ResourceStatusDto.class)
            return ResourceStatusJaxbFactory.getMarshaller();
        else
            return null;
    }       
    }
    

    I’ve got Jersey wired into Spring using the Jersey/Spring Servlet so any @Provider class that gets created by Spring is automatically recognized by Jersey. In my Spring applicationContext.xml all I have to do is instantiate the resource provider. It will, in turn, go grab the marshaller from the factory.

    3) The other thing that I found critical was that I had to create a package-info.java file in the root package containing my resource. Looks like this:

    /*
     * Note that this file is critical for ensuring that our ResourceDto object is
     * marshalled/unmarshalled with the correct namespace.  Without this, marshalled
     * classes produce XML files without a namespace identifier
     */
    @XmlSchema(namespace = XmlMetadataConstants.XML_SCHEMA_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) 
    package com.yourcompany.resource;
    
    import javax.xml.bind.annotation.XmlNsForm;
    

    At least I think that’s everything I needed to do, I can’t remember every single piece. I do remember that the package-info.java piece was the last critical cog that made it all come together.

    Hope that helps. I spent wayyyy too much time digging for the info on all this. Jersey was seductively simple before I wanted it to do proper xml schema validation (and decent error reporting for schema-invalid input). Once I started down that road Jersey went from brain-dead easy to decently hard. The majority of that difficulty was sussing out all the details from the variety of posts online. Hopefully this will help get you farther, quicker. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some WSDL from which I need to generate a web service implementation.
I have some classes that already use DOM4J to read XML files and provide
I have a client which connects to a Web service to get some information.
I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom,
So, i have some question about xml Documents in Java. Can i get all
I have a Java string of XML content. I use Velocity to generate some
I have some dates I have to represent in an XML file in a
Is there any way to speed up the initialization of javax.xml.bind.JAXBContexts with a large
I have a Scala representation of some XML (i.e. a scala.xml.Elem ), and I'd
I have written a simple HelloWorld web service. Which takes an ArrayList as parameter.

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.