0

I am working on a jersey - java project where I have to get the json data in string format and parse each data separately. I am able to get the response in string using post method. When I try to use JSON lib to parse the string data class not found exception is produced. I want the returned string to be split up. Below is my json.

{
    "startdate": "11/11/11",
    "enddate": "12/12/12",
    "operation_name": "task1",
    "user_id": "user1",
    "operation_key": ["KKMM-025", "SFF-025", "TTR-022"]
}

Resource method

@POST
@Path("OpertaionDetails")
@Consumes({MediaType.APPLICATION_JSON , MediaType.APPLICATION_XML})
public Response CreateOperations(String incoming_data) throws Exception
{
    try
    {
    JSONParser parse = new JSONParser(); // class not found exceptin i have added  the lib properly its working fine when it is used in main method of java.
    JSONObject jobj = (JSONObject)parse.parse(incoming_data);
    JSONObject  Jstart_date =  (JSONObject) jobj.get("startdate");
       // this data to be paresed

    System.out.print("incomingData"+incoming_data);

    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

    return Response.ok(incoming_data).build();

}
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Divakar R
  • 81
  • 5
  • 12
  • Have you tried to debug your code? If yes, what does it say? The error in the comments can also state that the jar isn't in your application's classpath? – robot_alien Dec 16 '18 at 12:55
  • yes , if i added JSONParser lib to parse JSON data, it say's class not found -org.json.simple.parser.JSONParser , but i have tested this main class it works fine i have imported all the required lib's – Divakar R Dec 16 '18 at 12:58
  • Try doing a project clean in your IDE followed by a project refresh... – robot_alien Dec 16 '18 at 12:59
  • i tried rebuilding my project. still i am getting the same error. – Divakar R Dec 16 '18 at 13:03
  • Can try: https://stackoverflow.com/a/32788866/1004631 – robot_alien Dec 16 '18 at 13:11
  • I have tried the above solution it dint work. The problem is that class won't execute only when i make a post request. if i run a normal class i am able to get all the details and work on it properly. – Divakar R Dec 16 '18 at 13:14

0 Answers0