I use the Gson library to convert objects to Json and vice versa. I copied the jars this library to a new lib folder and added it to the build path for the project in my Eclipse IDE .
I have one main class in which I convert the object to Json using toJson() , shown below, and send it to the servlet using Apache HttpClient HttpPost() .
Gson gson= new Gson(); String json = gson.toJson(names);
But in servlet I cannot convert Json to Object using fromJson() when I execute the following code.
Gson gson = new Gson(); Names names = gson.fromJson(s, Names.class);
This throws the following exception:
java.lang.NoClassDefFoundError: com/google/gson/Gson
Any idea why this might happen? Should I copy jars to the WebContent/WEB-INF/lib folder instead of a new folder named lib ?
source share