Reputation: 1912
How do I set the xml namespace when using Jersey, jaxb & jax-rs
Upvotes: 3
Views: 8623
Reputation: 148977
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:
@XmlSchema(namespace = "http://www.example.org",
elementFormDefault = XmlNsForm.QUALIFIED)
package org.example;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlNsForm;
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:
@XmlType(namespace="http://www.example.org/foo")
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:
Upvotes: 6