如何解决球衣的EntityHolder类型的层次结构
||@XmlRootElement(name = \"request\")
@XmlAccessorType(XmlAccessType.FIELD)
@JSONConfigurable
public class InteractionRequest {
@XmlElement(name = \"skill\")
protected String skillName;
}
@XmlRootElement(name = \"request\")
@XmlAccessorType(XmlAccessType.FIELD)
@JSONConfigurable
public class InteractionChatRequest extends InteractionRequest {
@XmlElement
@XmlJavaTypeAdapter(LPStringsXmlAdapter.class)
@XmlElementWrapper(name = \"preChatLines\")
protected List<String> line;
}
和2种用法:
@PUT
@Consumes({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
public Response postExitSurvey(EntityHolder<InteractionRequest> ent) {
InteractionRequest request = ent.getEntity();
return null;
}
@POST
@Consumes({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
public Response interactionRequest(EntityHolder<InteractionChatRequest> ent) {
InteractionChatRequest params = ent.getEntity();
return null;
}
现在,在两种情况下,实体所有者都持有InterationRequest对象,该对象在第二种用法中导致ClassCastException。
知道为什么吗? Jersey是否不应该将实体转换为我声明的类型?
在这种情况下,甚至可以进行等级划分吗?
谢谢,
乌迪
解决方法
您对JAXB注释有问题:
InteractionRequest
和InteractionChatRequest
都用@XmlRootElement(name = \"request\")
注释。因此它们具有相同的根元素,这使得JAXB无法区分它们。
尝试将InteractionChatRequest
更改为@XmlRootElement(name = \"chat-request\")
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。