public static void main(String[] args) {
CustomerInfo cus = new CustomerInfo();
cus.setName(“aa”);
JSONObject cusstr = JSONObject.fromObject(cus);
String str = “CustomerInfo”;
try {
Class<?> cl = Class.forName(str);
JSONObject.toBean(cusstr, cl.getClass()); //这里报错
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
Object net.sf.json.JSONObject.toBean(JSONObject jsonObject, Class beanClass)
错误信息提示如下:
net.sf.json.JSONException: java.lang.SecurityException: Can not make a java.lang.Class constructor accessible
at net.sf.json.JSONObject.toBean(JSONObject.java:302)
at net.sf.json.JSONObject.toBean(JSONObject.java:247)
at com.ruijie.common.util.StringUtils.jsonToEntity(StringUtils.java:85)
at com.ruijie.csc.center.customer.service.impl.CustomerInfoServiceImpl.main(CustomerInfoServiceImpl.java:145)
Caused by: java.lang.SecurityException: Can not make a java.lang.Class constructor accessible
at java.lang.reflect.AccessibleObject.setAccessible0(AccessibleObject.java:118)
at java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:108)
at net.sf.json.util.NewBeanInstanceStrategy$DefaultNewBeanInstanceStrategy.newInstance(NewBeanInstanceStrategy.java:56)
at net.sf.json.JSONObject.toBean(JSONObject.java:296)
… 3 more