I'm generating XML using JAXB. But JAXB is generating an empty Tag closing it self. But my client want separate empty tag. I know both are equals but he is not agree with me. please any one suggest the solution. Thanks.
Sample code:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"currencyCode",
"discountValue",
"setPrice",
"spendLowerThreshold",
"spendUpperThreshold",
"discountApportionmentPercent",
"discountApportionmentValue"
})
@XmlRootElement(name = "countryData")
public class CountryData {
protected String currencyCode;
protected String discountValue = "";
protected String setPrice = "";
protected String spendLowerThreshold = "";
protected String spendUpperThreshold = "";
protected String discountApportionmentPercent = "";
protected String discountApportionmentValue = "";
// Setters and Gettres
}
Actual Output:
<currencyCode>GBP</currencyCode>
<discountValue/>
<setPrice/>
<spendLowerThreshold/>
<spendUpperThreshold/>
<discountApportionmentPercent>0.0</discountApportionmentPercent>
<discountApportionmentValue/>
Expected Output:
<currencyCode>GBP</currencyCode>
<discountValue></discountValue>
<setPrice></setPrice>
<spendLowerThreshold></spendLowerThreshold>
<spendUpperThreshold></spendUpperThreshold>
<discountApportionmentPercent>0.0</discountApportionmentPercent>
<discountApportionmentValue></discountApportionmentValue>
Code for Marshalling:
try {
Marshaller marshaller = JAXBContext.newInstance(CountryData.class).createMarshaller();
ByteArrayOutputStream os = new ByteArrayOutputStream();
marshaller.marshal(countryData , os);
log.debug("The PPV request raw XML -> " + os.toString());
} catch (JAXBException e) {
// nothing to do
}
I'm Using JDK 6.0