Reputation: 4454
Please shed some light on JAXBContext configutation. Given:
com.mycompany.user01234
with several
JAXB-annotated classes@XmlType
Customer marshals instance of com.mycompany.user01234.UserClass1.class
to the server via web service endpoint. On the server side I do the following:
JAXBContext jbc = JAXBContext.newInstance("com.mycompany.user01234")
Unmarshaller um = jbc.createUnmarshaller();
JAXBElement<Object> element = um.unmarshal(source, Object.class);
Object customerInput = element.getValue();
And it works fine ONLY if I patch customer library with following package-info.java
:
@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED)
package com.mycompany.user01234;
To my shame I havent found any clear explanation of what this @XmlNsForm
annotation is and how it affects unmarshalling process. This is the first question.
The second question is whether it is possible (in the given layout) to put that QUALIFIED
value into some properties or defaults for JAXBContext
or use other non-declarative means allowing to get rid of package-info.java
.
Many thanks in advance!
Upvotes: 1
Views: 1958
Reputation: 137557
It corresponds exactly to the elementFormDefault
attribute of an <xs:schema>
element (i.e., the top-level element of an XML Schema document). What it does (with that constant) is state that elements from the namespace defined by the schema should be rendered with a qualifier (i.e., as <foo:bar>
instead of <bar>
); the exact way that the namespace is declared will also vary between the two styles. In terms of the XML infoset, the two styles are completely equivalent; if namespaces are declared correctly in the XML, JAXB should be equally happy (I believe it should only use the value when serializing).
You might want to try making your JAXBContext
by passing in the class that you are expecting so that you are a little less reliant on discovery code (assuming it's a FooBar
class that's really being produced):
JAXBContext jbc = JAXBContext.newInstance(FooBar.class);
FooBar customerInput = (FooBar) jbc.createUnmarshaller().unmarshal(source);
(The above code is abstracted from things that I do in my code's test suite that definitely already work.)
Upvotes: 2