如果需要改輸出XML的字符編碼,可以添加屬性JAXB_ENCODING
:
@Test
public void test2() throws JAXBException {
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "ISO-8859-1");
marshaller.marshal(one, System.out);
}
得到的結(jié)果:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<one>
<name>Test one</name>
</one>
已經(jīng)不再是默認的UTF-8
。
更多建議: