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
随机推荐
- 实时流处理Storm、Spark Streaming、Samza、Flink孰优孰劣
对于一个成熟的消息中间件而言,消息格式不仅关系到功能维度的扩展,还牵涉到性能维度的优化.随着Kafka的迅猛发展,其消息格式也在不断的升级改进,从0.8.x版本开始到现在的1.1.x版本,Kafka的 ...
- Codeforces Round #281 (Div. 2) B 模拟
B. Vasya and Wrestling time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- poj1679 次最小生成树 kruskal(暴力枚举)
Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...
- 【ZOJ4070】Function and Function(签到)
题意:求 k 层嵌套的 f(x) 0<=x,k<=1e9 思路:迭代不会很多次后函数里就会=0或者1,再看层数奇偶直接返回答案 #include<cstdio> #includ ...
- yii 用户登录验证(cwebuser) yii 用户登录 (记)
yii 的确是一个强大而臃肿的框架,简单的小项目,或者只做后台接口调用的项目,建议不要用. 今天记录一下yii使用中cwebuser(Yii::app()->user->login())登 ...
- 《Linux命令行与shell脚本编程大全 第3版》创建实用的脚本---11
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- UVALIVE 2927 "Shortest" pair of paths
裸的费用流.一开始因为这句话还觉得要拆点 样例行不通不知道这句话干啥用的.Further, the company cannot place the two chemicals in same dep ...
- error while loading shared libraries:libmysqlclient.so.18 错误
error while loading shared libraries:libmysqlclient.so.18错误 新手安装php的时候如果出现这种问题,解决办法很简单,就是查看你的mysql安装 ...
- J.U.C并发框架源码阅读(五)Semaphore
基于版本jdk1.7.0_80 java.util.concurrent.Semaphore 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is sub ...
- (16)C#继承
继承格式 class 子类:父类 { ....... } 1.子类能够继承父类所有的字段和方法. class Program { class Father { ; public void b() { ...