I am using JAXB / Moxy to marshal a class in XML. When the root element contains only the attribute, the output is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<procedure xmlns="http://xml.test.com/api/request" name="TestProcedure"/>
The required output contains a closing tag for the procedure:
<?xml version="1.0" encoding="UTF-8"?>
<procedure xmlns="http://xml.test.com/api/request" name="TestProcedure"></procedure>
This is sent to a third-party system. Although both are well-formed XML, it still needs a closing tag.
I saw this post: JAXB organizes XML differently with OutputStream and StringWriter
but did not see the difference in output between the output stream and strings when running locally.
This, apparently, applies only to elements and attributes, but not to the root element:
Represent a null value as an empty element in xml jaxb
I still configured DescriptorCustomizer and looked at the ClassDescriptor in the debugger, but did not see any properties that can be set as XMLDirectMapping.
My domain object looks like
@XmlRootElement(name = "procedure")
public class ProcRequest {
protected String procName;
protected String requestId;
protected List<Param> parameter;
@XmlAttribute
public String getProcName() {
return procName;
}
public void setProcName(String procName) {
this.procName = procName;
}
@XmlAttribute
public String getRequestId() {
return requestId;
}
public void setRequestId(String requestId) {
this.requestId = requestId;
}
@XmlElement
public List<Param> getParam() {
if (this.param == null) {
this.param = new ArrayList<Param>();
}
return param;
}
public void setParam(List<Param> param) {
this.param = param;
}
}
And my service contains:
ProcRequest procRequest = new ProcRequest();
procRequest.setProcName("TestProcedure");
JAXBContext jaxbContext = JAXBContext.newInstance(ProcRequest.class);
Marshaller moxyMarshaller = jaxbContext.createMarshaller();
moxyMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
moxyMarshaller.marshal(procRequest, System.out);
Are there any properties or attributes that can be set to force the closing tag to close at the end, similar to Marshaller.JAXB_FORMATTED_OUTPUT? Or any other suggestions?