I would recommend reading in Request and Response Objects in JAX-RS. You should also read section 3.3 of the JAX-RS specification as it covers the (very) technical aspects of how parameters are handled in JAX-RS. In the simplest case, you can simply provide a string parameter for your resource method, and input data (JSON) will be saved in it:
@POST @Produces({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON }) public String AuthMySQL(String json) { System.out.println("The JAX-RS runtime automatically stored my JSON request data: " + json); }
Of course, this does not affect the automatic mapping that JAX-RS can provide. When properly configured, the runtime can actually deserialize the incoming data directly into the Java class (provided that you created it). So, for example, given the following class:
class LoginData { private String email; private String password;
You can choose to marshal the request data directly in it as such:
@POST @Produces({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON }) public String AuthMySQL(LoginData data) { System.out.println("The JAX-RS runtime automatically deserialized my JSON request data: " + data); }
To successfully accomplish this, you need to include jersey-json in your application.
source share