JSONUtil.bean2Json()报Property 'key' of class has no read method. SKIPPED的问题处理
错误警告信息描述:
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的问题处理的更多相关文章
- CCLuaObjcBridge调Objective-C方法传索引数组报invalid key to 'next'错调试
CCLuaObjcBridge是cocos2d-x系列引擎与Objective-C进行交互的"桥梁",老廖的quick-cocos2d-x在其framework进行了简单了封装,封 ...
- Xcode报错Expected selector for Objective-C and Expected method body
昨天把键盘拿起来拍一下清清灰,然后就发现Xcode报错了,Xcode报错Expected selector for Objective-C and Expected method body,也不知道什 ...
- 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 将秘钥复制粘贴到文本编辑器中,再粘贴复制到
- Jenkins构建从github上克隆时,报Host key verification failed.
首先在本地通过CMD执行git clone xxxxx时,可以成功的通过免密(SSH_KEY)克隆下来代码,但是通过Jenkins克隆时,就报如下信息: Cloning into 'GitHub'.. ...
- python3 load Iris.data数据集出现报错key words: b'Iris-setosa'
通过搜索原因,发现有可能是在对文件读取是编译出现了问题,并且Keyword中提示b'Iris-setosa',而我们的string转float函数中没有字母b,很奇怪.所以尝试将转换函数所有的stri ...
- clientdataset新增append新增多条记录的时候报错 key valation
在前面加上两句 adsDetail.Active := False; adsDetail.CreateDataSet;
- php中直接执行mysqli_init()也是报Property access is not allowed yet的错误。
xdebug.auto_trace = On 和 xdebug.profiler_enable = On注释掉就OK了,不知道这两个配置项是干嘛的
- tensorflow报错 Key Conv/biases not found in checkpoint
可能的解决方法: 删除训练文件夹中的旧模型
- idea -- spring datasource配置文件不显示datasource.properties文件对应属性的值,错误提示cannot resolve property key
原文:https://yq.aliyun.com/articles/657711 点击 文件 顶部的 蓝色 MVC application context,修改为Local File
随机推荐
- [SDOI2015][bzoj3990] 序列 [搜索]
题面 传送门 思路 首先,这道题目有一个非常显然(但是我不会严格证明,只能意会一下)的结论:一个合法的操作序列中,任意两个操作是可以互换的 那么,这个结论加上本题极小的数据范围,为什么不搜索一下呢? ...
- java反射调用私有方法和修改私有属性
//调用私有方法package com.java.test; public class PrivateMethod { private String sayHello(String name) { r ...
- Codeforces Round #359 (Div. 2) C
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- win2008服务器信任问题
右键计算机,管理,在第一个页面里面有个安全信息,里面的右边有一个配置IE ESC ,点击他后会出现一个窗口,在那里面选择禁用即可!
- shell-总结【摘录】
阅读目录 1. Shell简介 2. 几种常见的Shell 3. 编译型语言和解释型语言的区别 4. 什么时候使用Shell? 5. 第一个Shell脚本 6. Shell变量 7.Shell特殊变量 ...
- php 内核变量 引用计数器写时复制
写时复制,是一个解决内存复用的方法,就是你在php语言层,如$d=$c=$b=$a='value';把$a赋给另一个或多个变量,这时这个变量都只占用一个内存块,当其中一个变量值改变时,才会开辟另一个内 ...
- ef unitofwork 主从表更新
readonly UnitOfWork _u = new UnitOfWork(); public M Get(int id) { return _u.T_MtnContractRepository( ...
- linux内核情景分析之execve()
用来描述用户态的cpu寄存器在内核栈中保存情况.可以获取用户空间的信息 struct pt_regs { long ebx; //可执行文件路径的指针(regs.ebx中 long ecx; //命令 ...
- 用户空间缺页异常pte_handle_fault()分析--(上)【转】
转自:http://blog.csdn.net/vanbreaker/article/details/7881206 版权声明:本文为博主原创文章,未经博主允许不得转载. 前面简单的分析了内核处理用户 ...
- 网站开发只需数小时?Meteor 说这才是未来
原文: http://www.geekpark.net/topics/211573/ 那个想要挑战过去数十年沿用至今的网站开发模式的新势力来了. Meteor 是从 YC 孵化而出的现代网站开发平台, ...