fastjosn转换成字符串时首字母大小写问题
2017-03-30 14:23
1881 查看
fastjson输出字符串默认首字母小写,如果想要大写(和bean一致),需要使用如下配置。
TypeUtils.compatibleWithJavaBean = true;
之前使用的1.1.*版本,该版本发现注入漏洞,公司统一升级。发现升级为1.2.28 后引入了一个bug。
前提:使用了fastjson某些配置。
例:在1.1.*版本中使用如下配置方式,结果正常。
程序在service或controller静态方法中设置的参数。
static {
TypeUtils.compatibleWithJavaBean = true;
}
升级后到1.2.28,结果错误。调试时发现TypeUtils.compatibleWithJavaBean在启动时已设置为true,在构造json串时为false。
原因:
1.2.28中IOUtils类下面方法会在第一次调用时执行,因此会覆盖在service或controller中的设置。 1.1.*版本无此方法。
static class
PropertiesInitializer {
PropertiesInitializer() {
}
publicvoid autoConfig(){
IOUtils.loadPropertiesFromFile();
TypeUtils.compatibleWithJavaBean =
"true".equals(IOUtils.getStringProperty("fastjson.compatibleWithJavaBean"));
TypeUtils.compatibleWithFieldName =
"true".equals(IOUtils.getStringProperty("fastjson.compatibleWithFieldName"));
}
}
解决办法:
增加配置文件(fastjson.properties),实际内容为“fastjson.compatibleWithJavaBean=true”。
也许还有其他方法,旺告知。
TypeUtils.compatibleWithJavaBean = true;
之前使用的1.1.*版本,该版本发现注入漏洞,公司统一升级。发现升级为1.2.28 后引入了一个bug。
前提:使用了fastjson某些配置。
例:在1.1.*版本中使用如下配置方式,结果正常。
程序在service或controller静态方法中设置的参数。
static {
TypeUtils.compatibleWithJavaBean = true;
}
升级后到1.2.28,结果错误。调试时发现TypeUtils.compatibleWithJavaBean在启动时已设置为true,在构造json串时为false。
原因:
1.2.28中IOUtils类下面方法会在第一次调用时执行,因此会覆盖在service或controller中的设置。 1.1.*版本无此方法。
static class
PropertiesInitializer {
PropertiesInitializer() {
}
publicvoid autoConfig(){
IOUtils.loadPropertiesFromFile();
TypeUtils.compatibleWithJavaBean =
"true".equals(IOUtils.getStringProperty("fastjson.compatibleWithJavaBean"));
TypeUtils.compatibleWithFieldName =
"true".equals(IOUtils.getStringProperty("fastjson.compatibleWithFieldName"));
}
}
解决办法:
增加配置文件(fastjson.properties),实际内容为“fastjson.compatibleWithJavaBean=true”。
也许还有其他方法,旺告知。
相关文章推荐
- 使用FastJson转换Json数据首字母大小写问题
- fastjson转换对象,属性首字母大小写的问题
- Codeforces - cAPS lOCK 大小写字母转换问题
- fastjson将bean转成字符串时首字母变小写问题
- 用Java将字符串的首字母转换大小写
- PHP将字符串首字母大小写转换
- fastjson将bean转成字符串时key首字母大小写问题
- C语言编程:字母大小写转换以及求字符串长度的两种方法
- fastjson将bean转成字符串时key首字母变小写问题
- 关于fastjson大小写转换问题的解决办法
- 字符串整体大小写转换,首字母大小写
- C中大小写字母转换的问题
- OC-字符串中大小写字母转换
- PHP将字符串首字母大小写转换
- C语言实现字符串英文字母大小写的转换
- PHP将字符串首字母大小写转换的实例
- fastJosn 转换对象为json格式字符串时, 空字段处理.
- 转换字符串里面的大小写字母
- PHP将字符串首字母大小写转换
- FastJson 输出值 首字母大小写问题