错误警告信息描述:

net.sf.json.JSONObject.defaultBeanProcessing(JSONObject.java:) 
Property 'handler' of class com.vrv.cems.mgr.domain.Manager_$$_javassist_182 has no read method. SKIPPED

问题分析:

JsonUtil.bean2Json(queryHistogramVO,new String[]{}));
将VO对象转换成JSON对象格式
jsonUtil包路径: queryHistogramVO 对象的属性和方法: public class HistogramVO {
private Integer userNum;
private Integer topCategory;
private Integer lastUserNum; public Integer getCurrentUser() {
return this.userNum;
}
public Integer getTopCategory() {
return topCategory;
}
public void setTopCategory(Integer topCategory) {
this.topCategory = topCategory;
}
public void setUserNum(Integer userNum) {
this.userNum = userNum;
}
public Integer getLastUserNum() {
return lastUserNum;
}
public void setLastUserNum(Integer lastUserNum) {
this.lastUserNum = lastUserNum;
}
}

  肉眼看上去这个类没有任何问题,仔细观察发现 属性"userNum"的get方法为"getCurrentUser()"

详细分析:

1、jsonutil调用类图分析:

  JsonUtil工具类是通过JSONObject.fromObject()方法转换的,查看源码,对fromObject详细分析发现代码:

      //这一句话很关键下面详细讲解
PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors( bean );
PropertyFilter jsonPropertyFilter = jsonConfig.getJsonPropertyFilter();
Class beanClass = bean.getClass();
for( int i = ; i < pds.length; i++ ){
String key = pds[i].getName();
if( exclusions.contains( key ) ){
continue;
} if( jsonConfig.isIgnoreTransientFields() && isTransientField( key, beanClass ) ){
continue;
} Class type = pds[i].getPropertyType();
//判断如果类的get方法存在则设置属性值
if( pds[i].getReadMethod() != null ){
//--------------中间的代码省略掉
setValue( jsonObject, key, value, type, jsonConfig );
}else{
//当get方法不存在报警告错误
String warning = "Property '" + key + "' has no read method. SKIPPED";
fireWarnEvent( warning, jsonConfig );
log.warn( warning );
}
}

  PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors( bean );

  这段代码是获取Bean所有的属性信息并将他封装成 PropertyDescriptor描述类。

  深入 getPropertyDescriptors()分析:

     if (beanClass == null) {
throw new IllegalArgumentException("No bean class specified");
} // Look up any cached descriptors for this bean class
PropertyDescriptor[] descriptors = null;
descriptors =
(PropertyDescriptor[]) descriptorsCache.get(beanClass);
if (descriptors != null) {
return (descriptors);
} // Introspect the bean and cache the generated descriptors
BeanInfo beanInfo = null;
try {
beanInfo = Introspector.getBeanInfo(beanClass);
} catch (IntrospectionException e) {
return (new PropertyDescriptor[]);
}
descriptors = beanInfo.getPropertyDescriptors();
if (descriptors == null) {
descriptors = new PropertyDescriptor[];
}

  上面是关键部分,他是通过java内省机制获取Bean的属性方法,并返回BeanInfo类。

  获取属性的规则:

  1、类中包含 公有get方法如: public String getCurrUser()

  2、类中包含公有的 set方法如:public void setName(String c)

  通过上面的分析,HistogramVO类有setUserNum()方法确没有对应的getUserNum()方法导致报""json.JSONObject - Property 'userNum' has no read method. SKIPPED"警告错误。

  添加getUserNum()方法即解决问题。

JSONUtil.bean2Json()报Property 'key' of class has no read method. SKIPPED的问题处理的更多相关文章

  1. CCLuaObjcBridge调Objective-C方法传索引数组报invalid key to &#39;next&#39;错调试

    CCLuaObjcBridge是cocos2d-x系列引擎与Objective-C进行交互的"桥梁",老廖的quick-cocos2d-x在其framework进行了简单了封装,封 ...

  2. Xcode报错Expected selector for Objective-C and Expected method body

    昨天把键盘拿起来拍一下清清灰,然后就发现Xcode报错了,Xcode报错Expected selector for Objective-C and Expected method body,也不知道什 ...

  3. github添加ssh key报错Key is invalid. Ensure you've copied the file correctly

    github添加ssh key的时候报错:Key is invalid. Ensure you've copied the file correctly 将秘钥复制粘贴到文本编辑器中,再粘贴复制到

  4. Jenkins构建从github上克隆时,报Host key verification failed.

    首先在本地通过CMD执行git clone xxxxx时,可以成功的通过免密(SSH_KEY)克隆下来代码,但是通过Jenkins克隆时,就报如下信息: Cloning into 'GitHub'.. ...

  5. python3 load Iris.data数据集出现报错key words: b'Iris-setosa'

    通过搜索原因,发现有可能是在对文件读取是编译出现了问题,并且Keyword中提示b'Iris-setosa',而我们的string转float函数中没有字母b,很奇怪.所以尝试将转换函数所有的stri ...

  6. clientdataset新增append新增多条记录的时候报错 key valation

    在前面加上两句 adsDetail.Active := False; adsDetail.CreateDataSet;

  7. php中直接执行mysqli_init()也是报Property access is not allowed yet的错误。

    xdebug.auto_trace = On 和 xdebug.profiler_enable = On注释掉就OK了,不知道这两个配置项是干嘛的

  8. tensorflow报错 Key Conv/biases not found in checkpoint

    可能的解决方法: 删除训练文件夹中的旧模型

  9. idea -- spring datasource配置文件不显示datasource.properties文件对应属性的值,错误提示cannot resolve property key

    原文:https://yq.aliyun.com/articles/657711 点击 文件 顶部的 蓝色 MVC application context,修改为Local File

随机推荐

  1. 一文看懂Kafka消息格式的演变

    摘要 对于一个成熟的消息中间件而言,消息格式不仅关系到功能维度的扩展,还牵涉到性能维度的优化.随着Kafka的迅猛发展,其消息格式也在不断的升级改进,从0.8.x版本开始到现在的1.1.x版本,Kaf ...

  2. BZOJ1017 [JSOI2008]魔兽地图DotR 【树形dp + 背包dp】

    题目链接 BZOJ1017 题解 orz hzwer 树形dp神题 设\(f[i][j][k]\)表示\(i\)号物品恰好花费\(k\)金币,并将\(j\)个物品贡献给父亲的合成时的最大收益 计算\( ...

  3. linux系统初始化——文件系统初始化步骤

    linux文件系统初始化步骤 System V init启动过程 概括地讲,Linux/Unix系统一般有两种不同的初始化启动方式. 1) BSD system init 2) System V in ...

  4. java中截取字符串的方式

    1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int len=s.length(); 2.ch ...

  5. HDU2041 简单DP+规律

    超级楼梯 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. NGINX: 优化 use 参数

    转自:http://blog.sina.com.cn/s/blog_5eaf88f10100gkrq.html Nginx use参数分析对比 下图对比了poll select epoll和kqueu ...

  7. 转载:GCC 提供的原子操作

    转载自:GCC 提供的原子操作 GCC 提供的原子操作 gcc从4.1.2提供了__sync_*系列的built-in函数,用于提供加减和逻辑运算的原子操作. 其声明如下: type __sync_f ...

  8. android hook 框架 ADBI 简介、编译、运行

    Android so注入-libinject2 简介.编译.运行 Android so注入-libinject2  如何实现so注入 Android so注入-Libinject 如何实现so注入 A ...

  9. 手一抖误删了根目录 /usr 之后的挽救过程

    一切悲剧来源于写的Shell没有好好检查,执行后把开发机的根目录 /usr 目录给删除了,而且是root执行,众所周知,/usr目录里有大量的应用层程序,删除之后导致大量命令无法使用,如 ssh / ...

  10. 谈谈dpdk应用层包处理程序的多进程和多线程模型选择时的若干考虑

    看到知乎上有个关于linux多进程.多线程的讨论:http://www.zhihu.com/question/19903801/answer/14842584 自己项目里也对这个问题有过很多探讨和测试 ...