gpt4 book ai didi

java - 带有 JAXB Random ClassCastException .. 的 Netbeans 无法转换为 com.sun.xml.bind.v2.runtime.reflect.Accessor

转载 作者:IT老高 更新时间:2023-10-28 20:51:20 26 4
gpt4 key购买 nike

我已经从 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 编译器配置中使用背书文件夹,但它仍然会发生

关于可能导致它的原因和可能的解决方案有什么想法吗?

谢谢你

最佳答案

用下面的代码解决

@BeforeClass
public static void init(){
System.setProperty( "com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize", "true");
}

@AfterClass
public static void revert(){
System.getProperties().remove("com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize");
}

参数也可以在JVM上使用

-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true

关于java - 带有 JAXB Random ClassCastException .. 的 Netbeans 无法转换为 com.sun.xml.bind.v2.runtime.reflect.Accessor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15569395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com