Error creating a Jsonobject object

Asked

Viewed 74 times

0

I’m trying to create a WebService return to me one or more data from the database, using as return JSON.

@Path("teste")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject teste() {

    JSONObject obj = new JSONObject();
    obj.put("teste", "teste 1");
    obj.put("teste2", "teste 2");

    return obj;

}

But when running through the URL, the following error occurs (I only took the first few lines):

 GRAVE: Servlet.service() for servlet [Jersey REST Service] in context with path [/TrabalhoWeb1] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException] with root cause
java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    at java.lang.ClassLoader.defineClass1(Native Method)

And when I do debug, the error occurs when it will instantiate the object JSONObject.

I have no idea what to do.

  • Ta remembering to import the class from the json object ?

  • @Felipedm Yes, The problem was with the library itself Json_lib, switched to the Gson google.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.