我正在尝试解组POJO生成xsds。
但是,我收到此错误
java.lang.ClassCastException:无法将动物投掷到Dog
这是我的代码。
Animal.java
public class Animal {
.... }
Dog.java
public class Dog Extends Animal {
public void validate() //Additional method
{
....
}}
JAXBContext
String input = "..."; //xml file
JAXBContext jc = JAXBContext.newInstance(Dog.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement<Dog> element = (JAXBElement<Dog> unmarshaller
.unmarshal(new ByteArrayInputStream(input.getBytes());
Dog dog = element.getValue();