Mapping mixed content type using XStream
A question on creating java class for following XML node which contains a error code and description on the same element. My question is about how could I map the error message details in the java class so XStream works for deserializing.
XML:
<response code="failure">
<![CDATA[error message details...]]>
</response>
Java:
@XStreamAlias("response")
p开发者_运维问答ublic class ErrorResponse {
@XStreamAlias("code")
@XStreamAsAttribute
private String code;
....
....
}
Thanks.
The following may be what you are looking for:
- XStream : node with attributes and text node?
However, I'll point out what you are trying to do is much easier with JAXB:
import javax.xml.bind.annotation.*;
@XmlRootElement(name="response")
@XmlAccessorType(XmlAccessType.FIELD)
public class ErrorResponse {
@XmlAttribute
private String code;
@XmlValue
private String description;
}
精彩评论