java.lang.ClassCastException:javax.xml.bind.JAXBElement无法转换为XX

时间:2018-07-27 13:37:44

标签: spring jaxb2

我正在开发一个jax-ws客户端,我正在尝试处理作为响应返回的ArrayList。

返回列表不是空的,我使用测试类进行了检查,但是当我尝试通过以下方式访问此列表时:

 System.out.println(releveBeanOut.getMyReleveInfo().getFacture().getValue().getItem().get(0).getRefImp());

我在控制台中收到此消息:

java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to Fact.

我有一个测试班:

@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootConfiguration
public class WSEspClientServiceTest {

    private final String EXISTING_USER_ACCESSKEY = "admin";
    private final String EXISTING_USER_CLIENTID = "yelkarkouri";

    private final String EXISTING_SEARCH_CRIT = "NUM_CLI";
    private final String EXISTING_SEARCH_CRTVALUE = "CLT-123";

    @Test
    public void releveWithExistingDataTest() {

        // ***** Call the service to generate the token
        AccessBeanIn accessBeanIn = new AccessBeanIn();

        ma.test.test.testclient.wsactest.ObjectFactory objectFactory = new ma.test.test.testclient.wsactest.ObjectFactory();
        JAXBElement<String> jaxbClientId = objectFactory.createAccessBeanInClientID(EXISTING_USER_CLIENTID);
        JAXBElement<String> jaxbAccesKey = objectFactory.createAccessBeanInAccessKey(EXISTING_USER_ACCESSKEY);

        accessBeanIn.setClientID(jaxbClientId);
        accessBeanIn.setAccessKey(jaxbAccesKey);
        WSAccesSoap wsAccesSoap = new WSAcces().getWSAccesSoap();
        String waterp_token = wsAccesSoap.generateToken(accessBeanIn).getToken();

        // ****************  Call the service to get list of invoices *****************
        WSEspServSoap wsEspServSoap = new WSEspServ().getWSEspServSoap();

        ObjectFactory objectFactory1 = new ObjectFactory();
        ReleveBeanIn releveBeanIn = new ReleveBeanIn();
        JAXBElement<String> convId = objectFactory1.createAbstractBeanConversationId("");

        JAXBElement<String> tokenJaxb = objectFactory1.createStatusBeanInToken(waterp_token);
        StatusBeanIn statusBeanIn = new StatusBeanIn();
        statusBeanIn.setToken(tokenJaxb);

        JAXBElement<StatusBeanIn> statusBeanInJaxb = objectFactory1.createAbstractBeanInSecurite(statusBeanIn);

        releveBeanIn.setCrit(EXISTING_SEARCH_CRIT);
        releveBeanIn.setValcrit(EXISTING_SEARCH_CRTVALUE);
        releveBeanIn.setSecurite(statusBeanInJaxb);
        releveBeanIn.setConversationId(convId);

        ReleveBeanOut releveBeanOut = wsEspServSoap.releve(releveBeanIn);



        Assert.assertEquals(
                releveBeanOut.getMyReleveInfo().getNbrImp().getValue(),
                String.valueOf(releveBeanOut.getMyReleveInfo().getFacture().getValue().getItem().size())
                );

    }

}

ps:测试通过。

0 个答案:

没有答案