String 데이터 유형에 대한 별명을 제공해야하는 xml로 오브젝트를 변환하려고합니다. 예를 들어 :XStream을 사용하여 데이터 유형의 별명을 지정하는 방법은 무엇입니까?
는public class ArrayTest
{
private int id=4;
public String area[];
public void setArea(String ar[])
{
area = ar;
}
}
XML 변환 클래스 개체와 같은 것입니다 : 나는대로 출력을 얻고있다
public class Test
{
public static void main(String args[])
{
String area[] = {"ABC","XYZ","PRQ"};
ArrayTest at = new ArrayTest();
at.setArea(area);
Xstream stream = new XStream(new staxDriver());
stream.alias("response",ArrayTest.class);
System.out.println(stream.toXML(at));
}
}
:
<?xml version="1.0" ?>
<response>
<id>4</id>
<area>
<code>ABC</code>
<code>XYZ</code>
<code>PRQ</code>
</area>
</response>
:
<?xml version="1.0" ?>
<response>
<id>4</id>
<area>
<string>ABC</string>
<string>XYZ</string>
<string>PRQ</string>
</area>
</response>
하지만 같은 출력을 원하는
XStream을 처음 사용하니 친절하게 도와주세요.
'당신을 위해 무엇을 찾고 있습니다. org/annotations-tutorial.html # ImplicitCollections – Albert
@Albert : 나는 또한 그 중 하나를 시도했지만 출력은 내가 기대하는 것이 아닙니다 ... – Samraan
@jjlema는 프로그래밍 방식으로 시도해 봅니다. – Albert