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
随机推荐
- c#后的完整cookie
http://www.cnblogs.com/top5/archive/2010/04/11/1709457.html c#设置 webbrowser的请求cookie,可以通过fiddler分析co ...
- python使用openpyxl操作excel
def initExcel(): file_path = "test.xlsx" file = load_workbook(file_path) table = file[&quo ...
- query的list()和iterate()区别 面试题
query的list()和iterate()区别 1.返回的类型不一样,list返回List,iterate返回iterator 2.查询策略不同. 获取数据的方式不一样,list会直接查询数据库,i ...
- IOS VLC编译步骤(包含移植和截图功能)
http://blog.csdn.net/Kan_Crystal/article/details/40424673 一.下载源码 先到VLC官网将源码下载到本机,以下链接为官网编译操作地址:https ...
- TMS320F28379D 使用心得之 SCI
原文地址https://blog.csdn.net/qq_39545674/article/details/82597106 一.SCI 简介SCI(Serial Communication Inte ...
- (10)ubuntu内核源码树
ubuntu内核源码树目录: root@ubuntu:/lib/modules/3.13.0-32-generic/build#
- BigDecimal 使用 静态方法总结
转自:http://myrecord.top/?post=18 -------------千位加, public static String getQs(String old){ boolean re ...
- 或许你不知道的10条SQL
一.一些常见的SQL实践 (1)负向条件查询不能使用索引 select * from order where status!=0 and stauts!=1 not in/not exists都不是好 ...
- python接口自动化9-https请求(SSL)【转载】
本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/python%E6%8E%A5%E5%8F%A3%E8%87%AA%E5%8A%A8%E ...
- mysql-MHA 故障收集
在manager 主机上开启监控服务,启动不了 [root@manager ~]# managerStart [] [root@manager ~]# managerStatus app1 is st ...