tags:

views:

17

answers:

1

Hi,

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:

Java:

@XStreamAlias("response") public class ErrorResponse { @XStreamAlias("code") @XStreamAsAttribute private String code;
.... .... }

Thanks.

A: 

The following may be what you are looking for:

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;

}
Blaise Doughan