Converter para String utilizando JAXB?

1 resposta
J

Pessoal, estou utilizando JAXB, sendo :

JAXBContext jc = JAXBContext.newInstance(Globals.XML_PROTESTO_DIR); Marshaller marshaller = jc.createMarshaller(); JAXBElement<Pedido> element = new ObjectFactory().createSolicitacaoProtesto(pedido); marshaller.marshal(element, System.out);

Preciso capturar esta saida de System.out e armazenar em uma String, alguem pode ajudar ?

marshaller.marshal(element, System.out);

1 Resposta

V

Cara,

Faz da seguinte forma:

JAXBContext jc = JAXBContext.newInstance(Globals.XML_PROTESTO_DIR);   
          Marshaller marshaller = jc.createMarshaller();   
          JAXBElement<Pedido> element = new ObjectFactory().createSolicitacaoProtesto(pedido);   
         
  

StringWriter sw = new java.io.StringWriter();
marshaller.marshal(element, sw);

String r = sw.toString();
Criado 16 de outubro de 2008
Ultima resposta 16 de out. de 2008
Respostas 1
Participantes 2