0

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")
public class ErrorResponse {
 @XStreamAlias("code")
    @XStreamAsAttribute
 private String code;  
....
....
}

Thanks.

thkala
  • 84,049
  • 23
  • 157
  • 201
Ajay
  • 1
  • 1
  • You may try this: http://fahdshariff.blogspot.com/2011/12/using-xstream-to-map-single-element.html Note this works only with Xstream 1.4.2 or above. – vijay Jan 13 '12 at 21:45

1 Answers1

0

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;

}
Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400