@XmlSeeAlso({ Dog.class, Cat.class })
public abstract class Animal {}
@XmlRootElement(name="dog")
public class Dog extends Animal {}
@XmlRootElement(name="cat")
public class Cat extends Animal {}
@WebService(name = "WebServiceDemo", serviceName = "WebServiceDemo")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class WebServiceDemo {
@WebMethod
public String service(@WebParam(name = "animal") Animal animal) {
System.out.println("animal service calling.....");
return animal;
}
}
现在,当我使用 Animal calss 作为参数从客户端调用此服务方法时,我遇到了错误-
引起:javax.xml.bind.UnmarshalException:无法创建 Animal 的实例 - 带有链接异常:com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext .java:616)在 com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244) 在 com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext .java:583) 在 com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:181) 在 com.sun.xml.bind.v2.runtime.unmarshaller.XsiTypeLoader.startElement(XsiTypeLoader .java:73) 在 com.sun.xml.bind.v2.runtime.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:455) 在 com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext。startElement(UnmarshallingContext.java:433) 在 com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71) 在 com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector。 startElement(SAXConnector.java:137) 在 com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240) 在 com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:277)在 com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:246) 在 com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:123) 在 com.sun.xml.bind .v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:314) 在 com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:293) 在 com.sun.xml.bind .v2.runtime.unmarshaller.UnmarshallerImpl。在 org.jboss.ws.core.jaxws.JAXBDeserializer.deserialize(JAXBDeserializer.java:71) 解组(UnmarshallerImpl.java:244)