Override declared encoding during unmarshalling with JAXB

前端 未结 1 669
暗喜
暗喜 2021-02-19 12:21

I have an XML file with its encoding set within it: but really file is encoded in UTF-8. Is there a way to ov

相关标签:
1条回答
  • 2021-02-19 12:40

    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

    • http://blog.bdoughan.com/2011/08/jaxb-and-java-io-files-streams-readers.html
    0 讨论(0)
提交回复
热议问题