com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value异常
springboot对象返回,一直报生成json异常,经过检查,发现是自己在做xss防护时对出参进行了json的处理(copy代码不可取,囧)
异常信息

这里进行了出参处理了,但实际上只要对入参处理就行了,把这个类改成入参处理即可
public class XssStringJsonSerializer extends JsonSerializer<String> {
@Override
public Class<String> handledType() {
return String.class;
}
@Override
public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
if (s == null) {
String encodedValue = StringEscapeUtils.escapeHtml4(s);
jsonGenerator.writeString(encodedValue);
}
}
即
//入参检查
public class XssStringJsonSerializer extends JsonDeserializer<String> {
public XssStringJsonSerializer(Class<String> string) {
super();
} @Override
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException
{
String value = jsonParser.getValueAsString();
if (value != null){
return StringEscapeUtils.escapeHtml4(value.toString());
}
return value;
} @Override
public Class<String> handledType() {
return String.class;
}
}
耽误了一小时代码排除,xss防护copy别人代码的。。。没理解就用的下场。。
com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value异常的更多相关文章
- com.fasterxml.jackson.core.JsonParseException: Unexpected character
com.fasterxml.jackson.core.JsonParseException: Unexpected )): was expecting double-quote to start fi ...
- java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
我从0手动搭建框架,启动tomcat,遇到这个错:java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingEx ...
- Springmvc4 com/fasterxml/jackson/core/JsonProcessingException
非常感谢: 谭卓博客 springmvc4 json springmvc4 集成hibernate4 出现 NoClassDefFoundError:com/fasterxml/jackson/cor ...
- springmvc java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
在hibernate spring springMVC整合的时候出现下面的情况: WARNING: Exception encountered during context initializatio ...
- Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'name': was expecting ('true', 'false' or 'null')
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'name': was expecting ( ...
- Java——使用ObjectMapper.writeValueAsString时报错The type com.fasterxml.jackson.core.JsonProcessingException cannot be resolved. It is indirectly referenced from required .class files
报错信息: The type com.fasterxml.jackson.core.JsonProcessingException cannot be resolved. It is indirect ...
- com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'user'
nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'user' 可能错误原因: ...
- com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 异常
分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519) 1.1.1. 前言 近期在使用ObjectMapper对象将jso ...
- com.fasterxml.jackson工具类
老版本的Jackson使用的包名为org.codehaus.jackson,而新版本使用的是com.fasterxml.jackson. Jackson主要包含了3个模块: jackson-core ...
随机推荐
- 英语cartialgenous鹿茸cartialgenous单词
鹿茸cartialgenous是雄鹿未骨化密生茸毛的幼角,主要从梅花鹿和马鹿头上采收,前者叫花鹿茸.黄毛茸,后者叫青毛茸.雄鹿到了一定年纪头上就会长角,初发时嫩如春笋,其表面上有一层纤细茸毛的嫩角就是 ...
- du查看某个文件或目录占用磁盘空间的大小
一.du的功能:`du` reports the amount of disk space used by the specified files and for each subdirectory ...
- redo log 重做日志
--------------------------------------------------2015-02-10---------------------------------------- ...
- python从入门到放弃之守护进程
# ### 守护进程 默认情况下,主进程要等待所有子进程执行完毕之后,才会关闭程序,释放资源守护进程进行在主进程代码执行结束之后,就直接关闭;守护进程守护的是主进程 语法: 进程.daemon = T ...
- Vue+ElementUI 导航组件
创建导航页组件 在components目录下新建一个navigation目录,在Navi目录中新建一个名为Navi.vue的组件.至此我们的目录应该是如下图所示: 然后我们修改main.js文件,修改 ...
- pandas 之 交叉表-透视表
import numpy as np import pandas as pd 认识 A pivot table is a data summarization tool(数据汇总工具) frequen ...
- 【MongoDB详细使用教程】三、高级查询
目录 1.使用比较运算符查询 2.使用关键字查询 2.1.in/not in 关键字 2.2.size 关键字 2.3.exists 关键字 2.4.or 关键字 3.模糊查询 4.查询结果排序 5. ...
- yum 安装apache php mysql
安装: yum install -y httpd php 查看版本:. rpm -qa httpd php httpd-2.2.15-54.el6.centos.x86_64 php-5.3.3-48 ...
- HTML与CSS学习笔记(1)
1.web三大核心技术? HTML CSS JavaScript 2.HTML基本机构和属性 HTML:超文本 标记 语言 超文本:文本内容+非文本内容(图片.视频.音频等) 标记:<单词> ...
- 在WEB显示实时视频流
转载自:https://www.jianshu.com/p/7ef5490fbef7 安装摄像头 这里使用的是树莓派的官方摄像头,使用普通的 USB 摄像头也可以,但前提是你能够搞的定它的驱动. 大概 ...