java - 使用 JAXB Marshaller 构建的 StringWrite 在使用 POSTMAN 查看时显示“<”而不是“<”
问题描述
我正在构建一个Web 服务和应用程序项目。服务将数据存储在包含 bookInfo 的本地 XML 文件中。Web 服务有一种方法可以查看存储在此 XML 文件中的所有 booksInfo。因此,为了读取 XML,我使用JAXB并将其解组为 POJO
解组
AllItems items = null;
try {
JAXBContext jaxbContext = JAXBContext.newInstance(AllItems.class);
Unmarshaller unMarshaller = jaxbContext.createUnmarshaller();
FileReader fileReader = new FileReader(new File("items.xml"));
items = (AllItems) unMarshaller.unmarshal(fileReader);
//items here is an object of the supposed to be the root element
编组
在此之后,我使用以下代码将其编组为 StringWrite:
StringWriter stringWriter = new StringWriter();
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(items, stringWriter);
}
catch (JAXBException | FileNotFoundException e) {
e.getMessage();
}
当我在控制台上查看输出时,一切看起来都很漂亮。如果我在 Web 浏览器上使用端点地址查看输出,它看起来仍然很漂亮。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<allItems>
<items>
<saleInfo>
<country>AU</country>
<saleability>FOR_SALE</saleability>
</saleInfo>
<status>back order</status>
<volumeInfo>
<authors>Liz Ellis</authors>
<industryIdentifiers>
<identifier>9781760780364</identifier>
<type>ISBN_13</type>
</industryIdentifiers>
<industryIdentifiers>
<identifier>1760780367</identifier>
<type>ISBN_10</type>
</industryIdentifiers>
<publishedDate>2018-04-24</publishedDate>
<publisher>Macmillan Publishers Aus.</publisher>
<title>If At First You Don't Conceive</title>
</volumeInfo>
</items>
但是当我使用POSTMAN或尝试使用Web 服务器控制台查看它时,问题就开始了。
不需要的输出如何使应用程序接收“<”而不是 &alt;”
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<allItems>
<items>
<saleInfo>
<country>AU</country>
<saleability>FOR_SALE</saleability>
</saleInfo>
<status>back order</status>
<volumeInfo>
<authors>Liz Ellis</authors>
<industryIdentifiers>
<identifier>9781760780364</identifier>
<type>ISBN_13</type>
</industryIdentifiers>
<industryIdentifiers>
<identifier>1760780367</identifier>
<type>ISBN_10</type>
</industryIdentifiers>
<publishedDate>2018-04-24</publishedDate>
<publisher>Macmillan Publishers Aus.</publisher>
<title>If At First You Don't Conceive</title>
</volumeInfo>
</items>
</allItems>
解决方案
推荐阅读
- ionic3 - ionic cordova:当我从文件选择器插件获取内容:// url 时,如何在 android 库的 img 标签中显示图像
- java - 如何选择 Kafka transaction.id
- java - 将 BytesWritable 转换为 com.vividsolutions.jts.geom.Geometry
- java - Spring没有在构造函数中创建带有布尔值的bean
- jquery - KendoFileUpload 不适用于 jquery 验证
- react-native - React Native:使用嵌套导航器时隐藏标题
- ios - 获取数字键盘以显示在输入类型=文本 iOS
- elasticsearch - mapper [clientip] 有不同的 [norms] 值,不能从禁用更改为启用]
- reactjs - 组织项目组件——这需要按字母顺序排列吗?
- ruby-on-rails - 配置 Capybara + Selenium 以通过 SSL 进行测试