I have an XML file with its encoding set within it: <?xml version="1.0" encoding="ISO-8859-15"?>
but really file is encoded in UTF-8. Is there a way to override encoding declared in XML file when unmarshalling it with JAXB?
You can unmarshal the content from a java.io.Reader
in order to supply the actual encoding:
Unmarshaller unmarshaller = jc.createUnmarshaller();
InputStream inputStream = new FileInputStream("input.xml");
Reader reader = new InputStreamReader(inputStream, "UTF-8");
try {
Address address = (Address) unmarshaller.unmarshal(reader);
} finally {
reader.close();
}
For More Information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With