杰克逊无法解析控制字符 [英] Jackson cannot parse control character

查看:86
本文介绍了杰克逊无法解析控制字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的API响应中,我具有control-p字符.杰克逊解析器无法序列化字符并引发错误

In my API response, I have control-p character. Jackson parser fails to serialize the character and throws an error

com.fasterxml.jackson.core.JsonParseException:非法未引用 字符((CTRL-CHAR,代码16)):必须使用反斜杠转义以 包含在字符串值中

com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 16)): has to be escaped using backslash to be included in string value

我调查发现,杰克逊图书馆实际上是在尝试获取ctrl-char.

I have investigated and found that Jackson library actually tries to catch for ctrl-char.

有人可以为此提出解决方案或解决方法吗?预先感谢.

Can anyone suggest solutions or work around for this? Thanks in advance.

推荐答案

我能够通过设置Feature.ALLOW_UNQUOTED_CONTROL_CHARS(

I was able to fix similar problem by setting Feature.ALLOW_UNQUOTED_CONTROL_CHARS (documentation) on JsonParser .

在我的情况下,代码如下:

The code in my case looks:

parser.setFeatureMask(parser.getFeatureMask() | JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS.getMask());

如其他人所述,这样的JSON是无效的,但是如果您没有机会更改JSON,这应该会有所帮助.

As stated by others, such JSON is invalid, but in case you have no chance to change JSON, this should help.

这篇关于杰克逊无法解析控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆