StringEcapeUtils不适用于•

时间:2017-07-26 09:57:29

标签: java elasticsearch logstash

我有一个HTML字符串存储在数据库中,如下所示

1&#149;DAY Brand<sup>&#174;</sup>Brand<sup>&#174;</sup>details&#151;\r\n<BR>\r\n<BR>\r\n<p>This Brand® is the best for you needs. Plus our Water® Technology is more comfort for you. Brand® offers the best in class mileage./p>\r\n<UL>   \r\n    <LI>Brand® is the #1 selling brand globally.\r\n    <LI>Experience all-day comfort with Water® Technology.\r\n  <LI>One of the highest levels of Mileage available in fuel.\r\n</UL>

我正在Spring Batch作业中从Database中读取这个字符串并创建一个结构如"string":"value"的json文件,其中我的值是我在上面提供的整个字符串。

现在使用logstash我正在尝试将此json推送到Elasticsearch。当我这样做时,我因为字符串exception=>#<LogStash::Json::ParserError: Invalid UTF-8 start byte 0xae而低于错误®所以在java中构建json文件时我尝试使用{{ 1}}要转义char org.apache.commons.text.StringEscapeUtils.escapeHtml4(),但由于我的字符串中有®,因此生成的内容类似于&#149; &#174;,现在当我在浏览器中使用此html时,此字符串未按预期显示。所以我想在java中首先使用&amp;#149; &amp;#174 and for ® it is coming like &reg;,这样我的字符串就会像

一样生成
org.apache.commons.text.StringEscapeUtils.unescapeHtml4(ofMyString)

我将再次使用escapeHtml4()来解决此问题。但这不起作用。我面临的问题是当我执行此操作时1DAY Brand<sup>®</sup>Brand<sup>®</sup>details<BR><BR><p>This Brand® is the best for you needs. Plus our Water® Technology is more comfort for you. Brand® offers the best in class mileage./p><UL> <LI>Brand® is the #1 selling brand globally. <LI>Experience all-day comfort with Water® Technology. <LI>One of the highest levels of Mileage available in fuel.</UL> .未在浏览器的html中显示。也没有对齐。 PFB Logstash脚本:

&#149;

有人可以帮忙吗。

0 个答案:

没有答案