Error in converting List to JSON in Java (3), javajson
1. Error description
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpherat net.sf.json.util.CycleDetectionStrategy.<clinit>(CycleDetectionStrategy.java:37)at net.sf.json.JsonConfig.<clinit>(JsonConfig.java:65)at net.sf.json.JSONArray.fromObject(JSONArray.java:105)at com.you.model.ListToJSON.main(ListToJSON.java:29)Caused by: java.lang.ClassNotFoundException: net.sf.ezmorph.Morpherat java.net.URLClassLoader$1.run(URLClassLoader.java:366)at java.net.URLClassLoader$1.run(URLClassLoader.java:355)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:354)at java.lang.ClassLoader.loadClass(ClassLoader.java:425)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)at java.lang.ClassLoader.loadClass(ClassLoader.java:358)... 4 more
2. Error cause
From the phrase "Caused by: java. lang. ClassNotFoundException: net. sf. ezmorph. Morpher", we can see that jar is missing.
3. Solution
Copy the ezmorph-1.0.6.jar to the lib directory
How to convert list into json in java
// Need to use json-lib.jar, you can download here: json-lib.sourceforge.net/
// Code instance
List <String> list = new ArrayList <String> ();
List. add ("abc ");
List. add ("123 ");
Net. sf. json. JSONArray jsonArray = net. sf. json. JSONArray. fromObject (list );
System. out. println (jsonArray. toString ());
Conversion from List set to json in java
Exception has told you, obviously the package is missing, should be missing the commons-beanutils.jar File