Netbeans with JAXB Random ClassCastException ..不能强制转换为 com.sun.xml.bind.v2.runtime.reflect.Accessor
2022-09-02 00:51:06
我已经从 SOAP 服务下载了 Soap 消息,并尝试通过返回下载的消息来模拟 Soap 服务。下面的代码显示了我如何将 Soap 消息取消到所需的响应中
public static DataClientType unmarshallFile(String fileName) throws Exception {
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLStreamReader xsr = xif.createXMLStreamReader(ClientSampleSoapResponseData.class.getResourceAsStream(fileName));
xsr.nextTag(); // Advance to Envelope tag
xsr.nextTag(); // Advance to Header
xsr.nextTag(); // Advance to Body tag
xsr.nextTag(); // Advance to getClientByAccountResponse
xsr.nextTag(); // Advance to content of getClientByAccountResponse
JAXBContext jc = JAXBContext.newInstance(GetClientByAccountResponse.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement<GetClientByAccountResponse> je = unmarshaller.unmarshal(xsr, GetClientByAccountResponse.class);
return je.getValue().getClientDataContract();
}
然而,我不断得到这个随机发生的ClassCastExeption。经过多次测试迭代后,它开始发生。有时清理和构建可以修复它,但有时它不起作用。
java.lang.ClassCastException: com.x.X.X.X.GetClientByAccountResponse$JaxbAccessorF_clientDataContract cannot be cast to com.sun.xml.bind.v2.runtime.reflect.Accessor
at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.instanciate(OptimizedAccessorFactory.java:188)
at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:180)
at com.sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.java:256)
at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.<init>(SingleElementNodeProperty.java:90)
我已经尝试了其他在线建议,例如恢复到旧的jaxb版本以及在maven编译器配置中使用认可的文件夹,但它仍然发生
关于可能导致它的原因和可能的解决方案的任何想法?
谢谢