错误警告信息描述:

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. 静态编译zsummerX

    下载 https://github.com/zsummer/zsummerX 下载 http://ftp.gnu.org/gnu/glibc/ ../configure --prefix=/home/ ...

  2. 在Linux上录制终端的操作

    在Linux上录制终端的操作 来源 http://blog.51cto.com/stuart/1831570 一.安装基础软件包 1 [root@test software]# yum install ...

  3. Hibernate中多对多的annotation的写法(中间表可以有多个字段)

    2011-07-04 6:52 一般情况下,多对多的关联关系是需要中间表的: 情况一:如果中间表仅仅是做关联用的,它里面仅有2个外键做联合主键,则使用ManyToMany(不用写中间表的Model,只 ...

  4. eclipse安装使用jetty

    安装: 直接从eclipse中的eclipse_market中下载即可,关键说下配置项目的访问路径:

  5. 百度经验:Win10查看已存储WiFi密码的两种方法

    方法一:网络和共享中心查询 具体步骤可以参考:Win10查看WIFI密码的方法 方法二:命令提示符查询 1.右键单击开始按钮,选择“命令提示符(管理员)” 2.输入如下命令(下图①号命令): nets ...

  6. 《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---47

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  7. java基础练习 15

    import java.util.Scanner; public class Fiftheen { /*有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下 ...

  8. 用css控制table td内文字超出隐藏

    (如有错敬请指点,以下是我工作中遇到并且解决的问题) 效果图: 重点是把table设置为table-layout: fixed; 超出的文字隐藏的效果才有. p标签超出的文字隐藏的效果不需要设置这个内 ...

  9. android launchmode singleinstance问题

    问题描述 最近测试关于launchmode的四种方式 默认模式 top singletask 都已经了解了 唯独这个instance模式 我的问题是 我们只作2个activity的假设A和B,其中A为 ...

  10. AC日记——算术天才⑨与等差数列 bzoj 4373

    4373 思路: 判断一个数列是否是等差数列: 1,最大值减去最小值==(区间个数-1)*k: 2,gcd==k: 3,不能有重复(不会这判断这一条,但是数据水就过了): 来,上代码: #includ ...