I am trying to unmarshall a XML document created from jersey JAXB annotated class.
JAXBContext jaxbCtx = JAXBContext.newInstance(MyClass.class);
Unmarshaller m = jaxbCtx.createUnmarshaller();
MyClass result = (MyClass) m.unmarshal(in)
MyClass looks something like:
@XmlRootElement(name = "my-class")
@XmlSeeAlso(SomeOther.class)
public class MyClass {
private Collection<SomeOther> result;
private URI uri;
private String errorMsg;
@XmlElement
public String getError() {
return errorMsg;
}
@XmlElement
public Collection<SomeOther> getResult() {
return // some Set<SomeOther>;
}
@XmlAttribute
public URI getUri() {
return uri;
}
The sample XML is as below:
<my-class uri="some uri">
<error></error>
<result>
<some other information in tags>
</result>
...
<result>
</result>
</my-class>
The object returned by jaxb unmarshaler contains all values as null;
Could somebody help here?
Thanks
Nayn
It is because you are missing the set methods. If you only provide the get methods, then JAXB considers this property to be write only.
If you do not wish to add set methods then you can add the following to your class:
And then annotate the fields instead of the properties.