Handle BOM in JAXB unmarshaller

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 03:22:27

问题


How can JAXB handle a string (of XML) that starts with a BOM? Is there a property to set or some configuration to skip the BOM when unmarshalling?Are there other JAXB implementations that could do that beside Oracle's implementation?


回答1:


If you're referring to a UTF-8 file with a BOM, then you will have to skip it yourself. It's fairly simple to come up with an InputStream class that checks the first two bytes for a BOM and skips them and otherwise wraps another InputStream. This has been documented in this SO answer and open source code for this purpose is available from GitHub.

If you're referring to some other encoding like UTF-16, the JRE should read the BOM from a UTF-16 stream and discard it itself.



来源:https://stackoverflow.com/questions/28152512/handle-bom-in-jaxb-unmarshaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!