1

Apache CXF/JAXB is not unmarshaling Japanese characters. If we are printing the xml using System.out.println output is coming properly like below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee id="1470">
    <designation>Eng</designation>
    <name>マデュ</name>
    <salary>20000.0</salary>
</employee>

If we are passing the same XML to CXF layer it is converting like below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee id="1470">
    <designation>Eng</designation>
    <name>???</name>
    <salary>20000.0</salary>
</employee>

How to solve this issue. Thanks in advance.

SMKReddy
  • 107
  • 3
  • 13
  • Where you saw the output xml with '???'? Can you share the code for the conversion? – Garry Jun 24 '15 at 10:44
  • JAXBContext pContext = JAXBContext.newInstance(target); sw = new StringWriter(); Marshaller marshaller = pContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(pObject, sw); – SMKReddy Jun 24 '15 at 11:20

1 Answers1

0

Can you try use PrintWriter on top of StringWriter?

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);

Can you try with XMLEventWriter to System.out?

        XMLEventFactory events = XMLEventFactory.newInstance();
        QName bar = new QName("urn:bar", "bar");
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
        XMLEventWriter writer = factory.createXMLEventWriter(System.out);


        JAXBContext pContext = JAXBContext.newInstance(target); 


        Marshaller marshaller = pContext.createMarshaller(); 
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); 
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 
        marshaller.marshal(pObject, writer); 

        writer.add(events.createStartDocument());
        writer.setDefaultNamespace("urn:bar");
        writer.add(events.createStartElement(bar, null, null));
        writer.add(events.createEndDocument());
        writer.flush();
Garry
  • 4,493
  • 3
  • 28
  • 48