gpt4 book ai didi

java - Apache CXF/JAXB 解码器将日语字符转换为 ?标记java

转载 作者:太空宇宙 更新时间:2023-11-04 13:44:15 25 4
gpt4 key购买 nike

Apache CXF/JAXB 不会解码日语字符。如果我们使用 System.out.println 打印 xml,输出将正常显示,如下所示。

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

如果我们将相同的 XML 传递到 CXF 层,它的转换如下。

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

如何解决这个问题。提前致谢。

最佳答案

你能尝试在 StringWriter 之上使用 PrintWriter 吗?

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

你能尝试使用 XMLEventWriter 到 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();

关于java - Apache CXF/JAXB 解码器将日语字符转换为 ?标记java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31024386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com