- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用这段代码:
JAXBContext jaxbContext = JAXBContext.newInstance( aObj.getClass());
Marshaller marshaller = jaxbContext.createMarshaller();
StringWriter sw = new StringWriter();
marshaller.marshal( aObj, sw);
return sw.toString();
我正在将一个 JAXB 对象直接序列化为一个 StringWriter:我的示例表明像“ü”这样的两个字节 UTF-8 字符被完美序列化,即它们按预期包含在生成的 java 字符串中。稍后,当通过套接字发送时,生成的 java 字符串被序列化为 aXml.getBytes( "UTF-8")。
如果上述编码器没有明确声明 UTF-8 字符编码,会不会有危险?
最佳答案
这并不危险。
By default, the Marshaller will use UTF-8 encoding when generating XML data to a java.io.OutputStream, or a java.io.Writer. Use the setProperty API to change the output encoding used during these marshal operations. Client applications are expected to supply a valid character encoding name as defined in the W3C XML 1.0 Recommendation and supported by your Java Platform.
jaxb.encoding
- 值必须是 java.lang.String编码 XML 数据时使用的输出编码。如果未指定此属性,Marshaller 将默认使用“UTF-8”。
关于java - JAXB 编码为 StringWriter : Is it necassary to declare the string encoding (e. g。 UTF-8)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35840666/
使用这段代码: JAXBContext jaxbContext = JAXBContext.newInstance( aObj.getClass()); Marshal
我是一名优秀的程序员,十分优秀!