1

My code is as follows:

@Path("/test")
public class Test {

@POST
@Path("/postSomething")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public RestMessageResponse postSomething(JSONObject inputJSONObject) {
   ..do something
}
}

when I send a post request to the appropriate url, it doesn't reach the code.

  • Can you please share the error or debug log ? – Ashu Jul 11 '18 at 11:40
  • there were no errors as such, although using postman this was the message that I received ---- Unrecognized field "projectId" (Class org.json.JSONObject), not marked as ignorable at [Source: org.apache.catalina.connector.CoyoteInputStream@396f60; line: 2, column: 16] (through reference chain: org.json.JSONObject["projectId"]) my request body contains a json with projectId as first key – Satishkumar sahu Jul 11 '18 at 11:53

1 Answers1

0

Why would you want to do this anyway?

Just send the plain JSON in your HTTPRequest and parse it. For me, this usually looks like this:

@RequestMapping(path= "/app/syncImages", method = RequestMethod.POST, produces = "application/json", consumes = "application/json") 
public ResponseEntity<?> someMethod(@RequestBody String body){              
    JSONObject request = new JSONObject(body);
    ...
}

Have you tried your code? Does it not work in some capacity?

Wep0n
  • 392
  • 3
  • 15
  • I recently looked the following post: https://stackoverflow.com/questions/14600510/how-to-send-and-receive-json-data-from-a-restful-webservice-using-jersey-api – Satishkumar sahu Jul 11 '18 at 17:23
  • I was trying to achieve something as shown in the above link but it didn't work for me. – Satishkumar sahu Jul 11 '18 at 17:24
  • Huh, maybe you can comment under the specific answer in the link to get the attention of the original poster, he can probably help out. I'll see if I can look into it myself. Funny enough, this: https://stackoverflow.com/a/44723288/7591918 is exactly what I do as well, since I am coming from a JAVA/NG Background in answering this question – Wep0n Jul 12 '18 at 05:57