我嘗試在scala中使用XStream,但它看起來像XSteam中的註釋不能在scala中工作。在下面的代碼中,只有@XStreamAlias工作,我也附上一個示例輸出,任何人都可以幫助嗎?XStream註釋在scala中不工作
@XStreamAlias("posts")
case class Posts(
@XStreamAsAttribute tag: String,
@XStreamAsAttribute total: String,
@XStreamAsAttribute user: String,
@XStreamImplicit(itemFieldName="post") posts: JList[Post])
@XStreamAlias("post")
case class Post(
@XStreamAsAttribute description: String,
@XStreamAsAttribute extended: String,
@XStreamAsAttribute hash: String,
@XStreamAsAttribute href: String,
@XStreamAsAttribute shared: String,
@XStreamAsAttribute tag: String,
@XStreamAsAttribute time: String)
<posts>
<tag>a</tag>
<total>b</total>
<user>c</user>
<posts>
<post>
<description></description>
<extended></extended>
<hash></hash>
<href></href>
<shared></shared>
<tag></tag>
<time></time>
</post>
</posts>
</posts>
從你在這裏給出的XML,我不認爲你可以使用'XStreamAsAttribute',但你想'XStreamAsAlias'。 'XStreamAsAttribute'適用於節點定義了屬性的地方,比如''。 –
是的,我想知道我怎樣才能使XStreamAsAttribute註解也可以工作 – zjffdu
然後你可以在'Posts'中將像'tag','total'這樣的元素作爲xml中的屬性。只有當您收到帶有上述屬性的源xml時,這才適用。但是你的示例沒有顯示這一點。 –