How do I set the xml namespace when using Jersey, jaxb & jax-rs
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
This is all done using JAXB annotations. The points below refer to your domain model.
Schema Level
You can specify schema level namespace information using the @XmlSchema package level annotation:
The above annotation leveraging elementFormDefault will default the namespace of all elements to “http://www.example.org“.
Type Level
You can override namespaces at the type level using the @XmlType annotation:
Property/Field Level
And/or you can specify namespace information on the annotations themselves:
Example
I have a blog post that demonstrates these concepts with an example: