Problema com JAXBElement

5 respostas
Edifran

Boa tarde Pessoal.

Estou no desenvolvimento da nota fiscal eletronica.
Tenho um método que faz a consulta do status do serviço, funcionando legal. Tenho este retorno do método.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <cUF>35</cUF>
            <versaoDados>2.00</versaoDados>
        </nfeCabecMsg>
    </soap:Header>
    <soap:Body>
        <nfeStatusServicoNF2Result xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <retConsStatServ versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe">
                <tpAmb>2</tpAmb>
                <verAplic>SP_NFE_PL_006h</verAplic>
                <cStat>107</cStat>
                <xMotivo>Serviço em Operação</xMotivo>
                <cUF>35</cUF>
                <dhRecbto>2011-03-17T13:54:50</dhRecbto>
                <tMed>1</tMed>
            </retConsStatServ>
        </nfeStatusServicoNF2Result>
    </soap:Body>
</soap:Envelope>

No entanto quando eu tento pegar esse xml e converter no objeto retConsStatServ, só é carregado o atributo versão, os outros ficam todos nulos.

nfeStatusServicoNF2 = consulta.nfeStatusServicoNF2(nfeDadosMsg, nfeCabecMsg);
            System.out.println("");
            JAXBElement<RetConsStatServ> jAXBElement = (JAXBElement<RetConsStatServ>) nfeStatusServicoNF2.getContent().get(0);
            RetConsStatServ retConsStatServ = jAXBElement.getValue();

Preciso da ajuda.

Obs: temos um projeto NFe no svn, caso alguém queira acesso ao projeto, enviar email para [email removido]

5 Respostas

luiz_renato

Edifran,

Quando vc pegar o resutlado , tenta usar Unmarshaller.

Edifran

Eu já tentei com Unmarshaller, também não deu certo, também só é carregado o atributo versão.

luiz_renato

Posta o trecho de código que usa o UnMarsheller.

Edifran

Segue trecho do código.

File file = new File("/home/francisco/file1.xml");
            JAXBContext context = JAXBContext.newInstance("br.com.flysolution.nfe2.statusservico");
            Unmarshaller unmarshaller = context.createUnmarshaller();
            RetConsStatServ retConsStatServ = unmarshaller.unmarshal(new StreamSource(file), RetConsStatServ.class).getValue();
            System.out.println(retConsStatServ.getCStat());//imprime null
            System.out.println(retConsStatServ.getCUF());//imprime null
luiz_renato

Cara,

Nao estou conseguindo acessar meu projeto , amanhã te mando um email e te dou um retorno.

Criado 17 de março de 2011
Ultima resposta 17 de mar. de 2011
Respostas 5
Participantes 2