我完全理解错误“发现无效的 XML 字符 (Unicode: 0x3)”
原因:org.xml.sax.SAXParseException:在文档的元素内容中发现了无效的 XML 字符 (Unicode: 0x3)。在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) ~[na:1.8.0_111] 在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper。致命错误(ErrorHandlerWrapper.java:177)~[na:1.8.0_111] 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)~[na:1.8.0_111] 在com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327) ~[na:1.8.0_111] 在 com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError (XMLScanner.java:1472) ~[na:1.8.0_111] 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver。
但我不敢相信我的眼睛一开始就是用这个角色编组的。
我已经编组了包含 .gz 文件部分的类,并且编组成功。当我试图解组它时,它给了我这个错误。
我使用的 marshaller 和 unmarshaller 来自 /com/sun/xml/internal/bind/v2/runtime/ -- rt.jar。
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(object, stringWriter);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.unmarshal(new StringReader(stringWriter.toString()));
这是明显的反身性问题,我不知道如何处理。
任何有同样问题的人,请告知如何克服它,希望无需更改编组器。
PS根据我的理解,编组者应该始终是自反的,并且不要编组它无法解组的东西。遗憾的是 rt.jar 不是。