项目场景:
同事做一个系统发布一个 公告栏 格式如下:
xxx:
xxxxxxx
2024年3月
想把这一串字符提交到后端去解析
问题描述
后端出现返回错误码400并出现警告
Resolved [org.springframework.http.converter.HttpMessageNotReadabeException: JSON parse error: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value;nested exception is com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 2, column: 18]]
原因分析:
HTTP 400错误,也称为Bad Request错误,通常意味着服务器理解了请求,但由于请求的语法不符合规范,无法正常处理。
无法解析字符串中的换行
解决方案:
添加fastjson坐标
pom.xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
允许特殊字符和转义符
application.yml
spring:
jackson:
parser:
allow-unquoted-control-chars: true