I have a code that calls this method. I am getting a ClassCastException while unmarshalling. I have passed correct classname while creating JAXBContext object.
public TestsuiteType parseTestSuiteXML(String path) throws JAXBException, FileNotFoundException {
JAXBContext context = JAXBContext.newInstance(TestsuiteType.class);
Unmarshaller um = context.createUnmarshaller();
TestsuiteType ts = (TestsuiteType) um.unmarshal(new FileReader("/Users/admin/Documents/workspace_Nishant_dev/Practice/xmls/TEST-junit.xml"));
List<TestcaseType> tcs = ts.getTestcase();
Iterator<TestcaseType> it = tcs.iterator();
while(it.hasNext()) {
TestcaseType tc = it.next();
if(tc.getContent().size() == 0) {
tcs.remove(tc);
}
}
return ts;
}
The exception trace for the above code :
Exception in thread "main" java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to com.jaxb.testjunit.TestsuiteType
at com.jaxb.testing.FailureProcessor.parseTestSuiteXML(FailureProcessor.java:49)
at com.jaxb.testing.FailureProcessor.main(FailureProcessor.java:24)
No comments:
Post a Comment