使用以下类构成我在 JAX-RS 调用 (CXF) 后传输到客户端的 JSON 消息结构,我收到
org.apache.cxf.jaxrs.client.ClientWebApplicationException: .Problem with reading the response message, class : class bg.vivacom.sel.dto.SELResponse, ContentType : application/json.
...
Caused by: org.codehaus.jackson.map.JsonMappingException: Can not construct instance of bg.vivacom.sel.dto.SELDTO, problem: abstract types can only be instantiated with additional type information
at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@16edbe39; line: 1, column: 157] (through reference chain: bg.vivacom.sel.dto.SELResponse["dto"])
返回的对象包含属性dto,它是一个接口
@XmlRootElement(name = "SELResponse")
public class SELResponse implements Serializable{
@XmlElement(name = "corelationID")
private String corelationID;
@XmlElement(name = "responseTimeStamp")
private String responseTimeStamp;
@XmlElement(name = "respStatusCode")
private String respStatusCode;
@XmlElement(name = "respStatusMessage")
private String respStatusMessage;
@XmlElement(name = "processStatus")
private ProcessStatus processStatus;
@XmlElement(name = "dto")
private SELDTO dto;
界面
public interface SELDTO extends Serializable {
是一种根据请求在我的答案中包含许多不同 DTO 的方法,例如
@XmlRootElement(name = "customerProfile")
public class CustomerProfileDTO implements SELDTO {
@XmlElement(name = "customerCode")
private String customerCode;
...
和
@XmlRootElement(name = "sms")
public class SmsDTO implements SELDTO {
@XmlElement(name = "From")
private String from;
...
任何想法我必须如何注释类,以便可以将响应正确设置为特定的对象类型。我知道它在重新创建不知道其类型的 dto 对象时需要其他信息,因此我尝试如下注释接口:
@XmlSeeAlso({CustomerProfileDTO.class, SmsDTO .class})
public interface SELDTO extends Serializable {
但我仍然得到这个问题。任何想法将不胜感激。