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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:26:08+00:00 2026-05-31T20:26:08+00:00

I have an Jersey API that returns Odata standard responses and consumes the same.

  • 0

I have an Jersey API that returns Odata standard responses and consumes the same. There are specific name spaces necessary for these responses. I have a package-info.java class:

@XmlSchema(
xmlns = {
    @XmlNs(namespaceURI = "http://www.w3.org/2005/Atom", prefix = ""),
    @XmlNs(namespaceURI = "http://schemas.microsoft.com/ado/2007/08/dataservices", prefix = "d"),
    @XmlNs(namespaceURI = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", prefix = "m")
},
namespace = "http://www.w3.org/2005/Atom",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED)
package my.package;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlSchema;

I use JAXB to automatically marshal and unmarshal the incoming request body and outgoing response for me. I have beans annotated for these purposes. Here is an example of one:

@XmlRootElement(name = "entry")
public class Entry
{
private String id;
private String title;
private Date updated;
private AtomLink link;
private Content content;

public Entry()
{
}

public Entry(final Content content)
{
this.content = content;
}

public Entry(final String id, final String title, final Date updated, final AtomLink link, final Content content)
{
this.id = id;
this.title = title;
this.updated = updated;
this.link = link;
this.content = content;
}

@XmlElement(name = "title")
public String getTitle()
{
return title;
}

public void setTitle(final String title)
{
this.title = title;
}

@XmlElement(name = "link")
public AtomLink getLink()
{
return link;
}

public void setLink(final AtomLink link)
{
this.link = link;
}

@XmlElement(name = "id")
public String getId()
{
return id;
}

public void setId(final String id)
{
this.id = id;
}

@XmlElement(name = "updated")
public Date getUpdated()
{
return updated;
}

public void setUpdated(final Date updated)
{
this.updated = updated;
}

@XmlElement(name = "content")
public Content getContent()
{
return content;
}

public void setContent(final Content content)
{
this.content = content;
}
}

The response comes across like this.

<ns4:entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:ns4="http://www.w3.org/2005/Atom">
<ns4:id>TEwxaTFL</ns4:id>
<ns4:title>my resource</ns4:title>
<ns4:link href="http://127.0.0.1:8080/API/resource(TEwxaTFL)" rel="self"/>
<ns4:content type="application/xml"> 
    <m:properties>
        <d:name>temp_170_ruleset</d:name>
        <d:shared>false</d:shared>
        <d:autorun>false</d:autorun>
    </m:properties>
</ns4:content>
</ns4:entry>

As you can see the other namespaces come across just fine. The default name space is coming back with a ns4 prefix rather than no prefix. I need it to be like this:

    <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<id>TEwxaTFL</id>
<title>my resource</title>
<link href="http://127.0.0.1:8080/API/resource(TEwxaTFL)" rel="self"/>
<content type="application/xml"> 
    <m:properties>
        <d:name>temp_170_ruleset</d:name>
        <d:shared>false</d:shared>
        <d:autorun>false</d:autorun>
    </m:properties>
</content>
</entry>

I’ve tried altering the package-info.java class to remove the name spaces:
removing

@XmlNs(namespaceURI = "http://www.w3.org/2005/Atom", prefix = ""),

and

namespace = "http://www.w3.org/2005/Atom", 

and removing one at a time. Doing these things never fix the namespace prefix but affected how posts happened – mapping was not possible.

Can anyone see what I’m missing here? I really don’t want to “manually” marshal every response. So I want to avoid a NamespacePrefixMapper solution, unless I can define that without manually marshaling the response. I’ve read where this is suppose to work.

I use Jersey 1.12, JAXB 2.2

–Outcome–
Using Moxy works. I was struggling with getting it to work because the imports used were still the JaxB that was not working for me. Syntactically using Moxy is the same so there was no overhead of updating code for us. We simply needed to add the jaxb.properties file and update our imports. The only other way we got rid of the default namespaces being like this (ns1, ns4, etc.) was to use XSL on the way out – and that sucks.

  • 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-31T20:26:09+00:00Added an answer on May 31, 2026 at 8:26 pm

    Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.

    package-info

    Using the following package-info with MOXy as the JAXB provider I was able to produce the XML that you are looking for. The line that is commented out is necessary until we finish the fix for the following bug: http://bugs.eclipse.org/365457

    @XmlSchema(
    xmlns = {
        //@XmlNs(namespaceURI = "http://www.w3.org/2005/Atom", prefix = ""),
        @XmlNs(namespaceURI = "http://schemas.microsoft.com/ado/2007/08/dataservices", prefix = "d"),
        @XmlNs(namespaceURI = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", prefix = "m")
    },
    namespace = "http://www.w3.org/2005/Atom",
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
    attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED)
    package forum9795350;
    
    import javax.xml.bind.annotation.XmlNs;
    import javax.xml.bind.annotation.XmlSchema;
    

    For More Information

    • http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html
    • http://blog.bdoughan.com/2011/11/jaxb-and-namespace-prefixes.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a REST web service with Jersey Server (that totally rocks !).
I have a Jersey client that is successfully calling a REST service and populating
I am using the Jersey Test Framework, that includes servlet-api 2.5 in the test
I have a Jax-RS Jersey web service on Weblogic. It runs fine but returns
I have a webservice function that returns something like the following: New Orleans, Louisiana
I have a REST API which is fairly typical, except that the id's of
Is there a way to have all the POJOs autogenerated that are needed when
I have developed a Jersey Resource class. Can someone please tell me how can
I have a Maven 2 RESTful application using Jersey/JAXB. I generate the JAXB beans
Have you ever seen any of there error messages? -- SQL Server 2000 Could

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.