Override declared encoding during disassembly with JAXB

I have an XML file with its encoding set inside it: <?xml version="1.0" encoding="ISO-8859-15"?> , But the file is actually encoded in UTF-8. Is there a way to override the encoding declared in the XML file when untying it with JAXB?

+8
java encoding jaxb unmarshalling
source share
1 answer

You can untie the content with java.io.Reader to provide 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(); } 

Additional Information

+18
source share

All Articles