0
@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>
예 ... 나는 다른 수업을 만들지 않기를 바랬습니다. 그러나 이것은 효과가있을 것입니다. 이것은 한 수업에서 모든 것을 할 수있는 방법을 찾지 못하면 내 계획 B가 될 것입니다. – gonzo