有没有办法在使用时为同一类型分配不同的名称@XmlElements
?我开始只是使用@XmlElement
. 做了一些阅读并找到@XmlElementWrapper
了,@XmlElements
但仍然无法获得我想要的输出。我意识到我可以为 2 制作不同的数据类型,但如果我可以使用注释来做到这一点,那就太好了。
当前迭代:
@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");
...
电流输出:
<Root>
<ContactInformation>
<LogicalOwner>should be inside name</LogicalOwner>
<LogicalOwner>should be insde of owner</LogicalOwner>
</ContactInformation>
</Root>
期望的输出:
<Root>
<ContactInformation>
<Name>should be inside name</Name>
<LogicalOwner>should be insde of owner</LogicalOwner>
</ContactInformation>
</Root>