Is there any way to assign different names to the same type when using @XmlElements
? I started off with just using @XmlElement
. Did some reading and found @XmlElementWrapper
and the @XmlElements
but still have not been able to get my desired output. I realize that I could just make different data types for the 2 but it would be sweet if I could just do this with annotations.
Current Iteration:
@XmlRootElement(name = "Root")
public class XmlTest {
@XmlElementWrapper(name="ContactInformation")
@XmlElements({
@XmlElement(name="Name"),
@XmlElement(name="LogicalOwner")
})
public List<String> contactInformation;
...
contactInformation = new ArrayList<>();
contactInformation.add("should be inside name");
contactInformation.add("should be insde of owner");
...
Current Output:
<Root>
<ContactInformation>
<LogicalOwner>should be inside name</LogicalOwner>
<LogicalOwner>should be insde of owner</LogicalOwner>
</ContactInformation>
</Root>
Desired Output:
<Root>
<ContactInformation>
<Name>should be inside name</Name>
<LogicalOwner>should be insde of owner</LogicalOwner>
</ContactInformation>
</Root>