@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;
}
And 2 usages:
@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;
}
Now, in both cases, the entity holder holds InterationRequest object which results in a ClassCastException in the second usage.
Any idea why? Shouldn’t Jersey cast the entity to the type I declare?
Is hierarchy even possible in this case?
Thanks,
Udi
You have a problem with the JAXB annotations: both
InteractionRequestandInteractionChatRequestare annotated with@XmlRootElement(name = "request"). So they have the same root element, which makes it impossible for JAXB to distinguish between them.Try to change the
InteractionChatRequestto@XmlRootElement(name = "chat-request").