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 ...
随机推荐
- (转)Unity与3ds Max的单位关系(使用FBX文件)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/a1780531/article/deta ...
- Telegram Android源码问题汇总 持续更新
libtgvoip目录为空 git clone下来的工程中带有submodule时,submodule的内容没有下载下来,执行如下命令 cd Telegram git submodule update ...
- Scrum冲刺博客
一.各个成员在Alpha阶段认领的任务 已完成 二.各个成员的任务安排 三.整个项目期的任务量 按实际考试情况以及开发情况决定,初始计划是完成登录以及个人目标版块的完整功能,其它版块共进,保证最终能够 ...
- 使用类似GeoJson的数据生成物体(建筑等)的功能逻辑
GeoJson作为一种模型传输格式, 用的最多的就是地图里面的各种简单模型了, 比如下图中很贴切的俄罗斯方块楼: 它的格式大概就是下面这样: { "type": "Fea ...
- Vuex操作步骤
概念流程图: 案例: (1)src/store/index.js导出仓库 (2)在入口文件引入仓库并派发到每个组件,在入口文件main.js引入,挂载到根组件上,方便以后使用this.$store调用 ...
- 201871010102-常龙龙《面向对象程序设计(java)》第十七周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- Druid(数据库连接池) 学习资料
学习资料 网址 官方文档 https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98 主流Java数据库连接池 ...
- Socket是什么(一)
网络编程就是编写程序使两台联网的计算机相互交换数据. 那么,这两台计算机之间用什么传输数据呢?首先需要物理连接.如今大部分计算机都已经连接到互联网,因此不用担心这一点. 在此基础上,只需要考虑如何编写 ...
- xgboost:
https://www.zybuluo.com/Dounm/note/1031900 GBDT算法详解 http://mlnote.com/2016/10/05/a-guide-to-xgboost- ...
- (转)Tomcat与Jetty区别
一.简介 Tomcat: Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta项目中的一个核心项目,由Apache.Sun和其他一些公司及个人共 ...