问题
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