具有JAXB Random ClassCastException的Netbeans ..无法转换为com.sun.xml.bind.v2.runtime.reflect.Accessor [英] Netbeans with JAXB Random ClassCastException ..cannot be cast to com.sun.xml.bind.v2.runtime.reflect.Accessor

查看:656
本文介绍了具有JAXB Random ClassCastException的Netbeans ..无法转换为com.sun.xml.bind.v2.runtime.reflect.Accessor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从SOAP服务下载了Soap消息,并尝试通过返回下载的消息来模拟Soap服务。以下代码显示了我如何将Soap消息解组为所需的响应

I have downloaded the Soap messages from a SOAP Service and trying to mock the Soap service by returning the downloaded messages. the following code shows how I am Unmarshalling the Soap message into the required Response

    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。经过多次测试迭代后,它开始发生。有时一个干净的构建修复它但有时它不起作用。

However I keep getting this ClassCastExeption which happens randomly. After a number of test iterations, it begins to happen. Sometimes a clean and build fixes it but sometimes it doesn't work.

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编译器配置中使用已签名的文件夹,但它仍然会发生

I have tried other online suggestions such as reverting to old jaxb versions and using endorsed folders in the maven compiler configuration but it still happens

关于可能导致它的原因和可能的解决方案的任何想法?

Any ideas on what could be causing it and possible solutions?

谢谢你

推荐答案

解决以下代码

@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");
}    

也可以使用

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

这篇关于具有JAXB Random ClassCastException的Netbeans ..无法转换为com.sun.xml.bind.v2.runtime.reflect.Accessor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆