JSON parsing exception-Net.sf.json.JSONException:java.lang.reflect.InvocationTargetException

Source: Internet
Author: User

Note: In the project, I use the original AJAX request data, Jsonobject did not help me to parse, when I did not give me an error, I was in the JUnit unit test when testing, found. Found many times, especially through the AJAX request, do not give us an error, very depressed, especially IE, There are some problems that need to be analyzed using Firefox's return results.

Of course, Firefox does not complain at times.

Exception stack:

net.sf.json.JSONException:java.lang.reflect.InvocationTargetException at Net.sf.json.jsonobject._frombean ( Jsonobject.java:953) at Net.sf.json.JSONObject.fromObject (Jsonobject.java:192) at Net.sf.json.jsonobject._processvalue (Jsonobject.java:2774) at Net.sf.json.jsonobject._setinternal (Jsonobject.java:2798) at Net.sf.json.JSONObject.setValue (Jsonobject.java:1507) at Net.sf.json.jsonobject._frombean (Jsonobject.java:940) at Net.sf.json.JSONObject.fromObject (Jsonobject.java:192) at Net.sf.json.jsonobject._processvalue (Jsonobject.java:2774) at Net.sf.json.JSONObject.processValue (Jsonobject.java:2833) at Net.sf.json.JSONObject.element (Jsonobject.java:1871) at Net.sf.json.JSONObject.element (Jsonobject.java:1849) at Net.sf.json.JSONObject.put (Jsonobject.java:2466) at Sys_bd.json.JsonService.getJsonStr (Jsonservice.java:8) at Com.bd.action.LockAction.queryMapByAttSuccess (Lockaction.java:442) at Com.db.action.LockActionTest.testEncapsulateLockAsJson (Lockactiontest.java:40) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (Method.java:30S) at org.junit.runners.model.frameworkmethod$1.runReflectiveCall (frameworkmethod.java:44) at Org.junit.internal.runners.model.ReflectiveCallable.run (Reflectivecallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively (Frameworkmethod.java:41) at Org.junit.internal.runners.statements.InvokeMethod.evaluate (Invokemethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored (Blockjunit4classrunner.java:79) at Org.junit.runners.BlockJUnit4ClassRunner.runChild (Blockjunit4classrunner.java:71) at Org.junit.runners.BlockJUnit4ClassRunner.runChild (Blockjunit4classrunner.java:49) at org.junit.runners.parentrunner$3.run (parentrunner.java:193) at org.junit.runners.parentrunner$1.schedule (parentrunner.java:52) at Org.junit.runners.ParentRunner.runChildren (Parentrunner.java:191) at org.junit.runners.parentrunner.access$(parentrunner.java:42) at org.junit.runners.parentrunner$2.evaluate (parentrunner.java:184) at Org.junit.runners.ParentRunner.run (Parentrunner.java:236) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (Junit4testreference.java:50) at Org.eclipse.jdt.internal.junit.runner.TestExecution.run (Testexecution.java:38) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (Remotetestrunner.java:467) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (Remotetestrunner.java:683) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (Remotetestrunner.java:390) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (Remotetestrunner.java:197) caused by:java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (Method.java:30S) at Org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod (Propertyutilsbean.java:1773) at Org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty (Propertyutilsbean.java:1132) at Org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty (Propertyutilsbean.java:686) at Org.apache.commons.beanutils.PropertyUtilsBean.getProperty (Propertyutilsbean.java:715) at Org.apache.commons.beanutils.PropertyUtils.getProperty (Propertyutils.java:290) at Net.sf.json.jsonobject._frombean (Jsonobject.java:928)    ... 37morecaused by:java.lang.IllegalArgumentException at Java.sql.Date.getHours (Date.java:182)    ... More
View Code

This problem describes the use of JSON to encapsulate an object, for a date format, to report the error.

Some people say that the object's Getter designation package (Java.uti.Date) is possible, but I found that the test can not.

My solution is reference: http://segmentfault.com/q/1010000000095526

Tool class: Using the Config object

 PackageSys_bd.json;ImportJava.text.SimpleDateFormat;ImportNet.sf.json.JSONObject;ImportNet.sf.json.JsonConfig;ImportNet.sf.json.processors.JsonValueProcessor; Public classJsonservice {PrivateJsonservice () {}Private Static FinalJsonconfig Jsonconfig =init (); Private Staticjsonconfig init () {jsonconfig jsonconfig=NewJsonconfig (); Jsonconfig.registerjsonvalueprocessor (java.util.Date.class,                Newjsonvalueprocessor () {PrivateSimpleDateFormat SD =NewSimpleDateFormat ("Yyyy-mm-dd");  PublicObject Processobjectvalue (String key, object value, Jsonconfig jsonconfig) { returnValue = =NULL? "": Sd.format (value); }                     PublicObject Processarrayvalue (object value, Jsonconfig jsonconfig) {return NULL;        }                }); returnJsonconfig; }     Public Staticstring Getjsonstr (String key, Object value) {//use the Config object.Jsonobject Jsonobject =Jsonobject.fromobject (value, jsonconfig); returnjsonobject.tostring (); }}

JSON parsing exception-Net.sf.json.JSONException:java.lang.reflect.InvocationTargetException

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.