You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue first manifested in 4.0.0 and is still present in 4.0.5. In 3.0.2 this issue does not happen.
If you have 3 objects, Parent (fields: ID), ChildA (fields: name), ChildB (fields: Id, name) when you try to marshal an instance of ChildA, the ID field from Parent will not be marshaled if the Id filed is defined in ChildB.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Parent", propOrder = {
"id"
})
@XmlSeeAlso({ChildA.class, ChildB.class})
public class Parent {
@XmlElement(name = "ID")
protected Integer id;
public Integer getID() {
return id;
}
public void setID(Integer value) {
this.id = value;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Request", propOrder = {
"objects"
})
@XmlRootElement(name = "Request")
public class Request {
@XmlElement(name = "Objects", required = true)
protected List<Parent> objects;
public List<Parent> getObjects() {
if (objects == null) {
objects = new ArrayList<>();
}
return this.objects;
}
}
test to manifest issue:
@Test
public void test() throws JAXBException {
ChildA child = new ChildA();
child.setName("test-name");
child.setID(1234);
Request req = new Request();
req.getObjects().add(child);
final Marshaller marshaller = JAXBContext.newInstance(Request.class).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
StringWriter stringWriter = new StringWriter();
marshaller.marshal(req, stringWriter);
String xmlAsString = stringWriter.toString();
System.out.println(xmlAsString);
}
Note: an instance of ChildB isn't even created and the issue manifests. I first noticed this with objects automatically generated from a SOAP WSDL, but I was able to reproduce it with these hand crafted objects.
The text was updated successfully, but these errors were encountered:
This issue first manifested in 4.0.0 and is still present in 4.0.5. In 3.0.2 this issue does not happen.
If you have 3 objects, Parent (fields: ID), ChildA (fields: name), ChildB (fields: Id, name) when you try to marshal an instance of ChildA, the ID field from Parent will not be marshaled if the Id filed is defined in ChildB.
Example XML, Parent.ID field missing:
Example XML, Parent.ID present when Id removed from definition of ChildB:
Sample code:
test to manifest issue:
Note: an instance of ChildB isn't even created and the issue manifests. I first noticed this with objects automatically generated from a SOAP WSDL, but I was able to reproduce it with these hand crafted objects.
The text was updated successfully, but these errors were encountered: