I'm trying to consume a webservice which I need to set the parameters of request using a element type "JAXBElement". I have this specific Object but I don't know how to convert my Object to JAXBElement. I've searched some relateds subjects but I didn't find any clear answer. What need I do to convert this object?
Asked
Active
Viewed 1,837 times
0
-
Possible duplicate of [convert object into JAXBElement](https://stackoverflow.com/questions/5702035/convert-object-into-jaxbelement) – Yserbius Mar 08 '18 at 21:43
1 Answers
0
XMLGenerator.class contains following code
public void generateXML() {
try {
List<JAXBClass> jaxbClassList= this.jaxbObjectList;
outputElement.setJAXBObject(jaxbClassList);
marshaller.setProperty("jaxb.formatted.output",Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "xsd location of the file used to create this xml");
marshaller.marshal(outputElement,new File("Example.xml"););
} catch (JAXBException e) {
e.printStackTrace();
}
}
JAXBClass.class
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "JAXBClass", propOrder = {
"referenceDate",
"roles",
"identifiers",
"name",
"address"
})
public static class JAXBClass{
@XmlElement(name = "ReferenceDate", required = true)
protected String referenceDate;
@XmlElement(name = "Roles", required = true)
protected RolesType roles;
@XmlElement(name = "Identifiers", required = true)
protected IdentifierType identifiers;
@XmlElement(name = "Name", required = true)
protected String name;
@XmlElement(name = "Address", required = true)
protected CounterPartyList.CounterPartyTO.Address address;
//setter and getters of the above variables
}
Map your input class with the variable in JAXBClass and you are good to write it in XML.
In Eclipse, You don't have to code the above class, Just right click on the xsd file and click on generate->JAXB classes and you have everything you need.
I hope this helps!

VijayD
- 826
- 1
- 11
- 33