Run: JSONArrayarrayJSONArrayfromObject (thisusers); the following error will be reported: netsfjsonJSONException: javalangreflectInvocationTargetExceptionusers is a list set solution 1: JSONArrayarr
Run:
JSONArray array = JSONArray. fromObject (this. users );
The following error is reported:
Net. sf. json. JSONException: java. lang. reflect. InvocationTargetException
Users is a list set.
Solution 1:
JSONArray array = JSONArray. fromObject (this. users. toArray ());
Solution 2:
Because the bean contains the Date Field and the data read from the database is java. SQL. date is assigned to java. util. date, an error occurred when converting to JSONArray. You can directly write it as new java when reading the Date from the database. util. date (rs. getDate ("date "). getTime), so there will be no errors;
Solution 3:
Date Format hibernate delayed Loading
1. Solution: Date Format
Private java. util. Date createTime;
If the data type of Date is declared only before the field, an exception may be thrown. In the Set or get method, if the data type of Date is declared, the package name is added.
2. Solution: hibernate delayed loading settings
Java code
JsonConfig cfg = new JsonConfig (); cfg. setExcludes (new String [] {"handler", "hibernateLazyInitializer "});
Example
Java code
/*** Datagrid easyui finds out the contact pager-public, and you can view the self-created Contact */@ Transactional (readOnly = true) public JSONArray datagrid (Pager page, User user User, detachedCriteria detachedCriteria) {// cascade, cannot be converted directly. You need to extract the List and put it into the map. JsonConfig cfg = new JsonConfig (); // filter the Association to avoid endless loops. net. sf. json. JSONException: java. lang. reflect. invocationTargetException cfg. setJsonPropertyFilter (new PropertyFilter () {public boolean apply (Object source, String name, Object value) {if (name. equals ("addressGroup") | name. equals ("user") | name. equals ("createTime") | name. equals ("birthday") {return true;} else {return false ;}}); // net. sf. json. JSONException: java. lang. reflect. invocationTargetException exception cfg. setExcludes (new String [] {"handler", "hibernateLazyInitializer"}); // loop call appears in javabean. Use excludes to kill parent or children // cfg. setExcludes (new String [] {"addressGroup"}); // net. sf. json. JSONException: java. lang. reflect. invocationTargetException Date Format Conversion error // cfg. setCycleDetectionStrategy (CycleDetectionStrategy. LENIENT); // cfg. registerJsonValueProcessor (Date. class, new DateJsonValueProcessor ("yyyy-MM-dd hh: mm: ss"); Pager pager = this. findAllByApprove (page, user, detachedCriteria); long total = pager. getTotalCount (); List list = pager. getResult (); Map Result = new HashMap (); Result. put ("total", total); result. put ("rows", list); JSONArray jsonArray = JSONArray. fromObject (result, cfg); return jsonArray ;}