I am a newbie to JSON. I wish to ask that how can I convert the following code from @GET to @POST so that I can retrieve the appdataid from user JSON input and not from the link.
AppDataService ads = new AppDataService();
@GET
@Path("/{appdataid}")
@Produces(MediaType.APPLICATION_JSON)
public AppData getAppData(@PathParam("appdataid")long appdataid){
return ads.getAppData(appdataid);
}
Code for AppDataService
public AppDataService(){
appdatas.put(1L, new AppData(1,"Success", " ", "123456"));
appdatas.put(2L, new AppData(2,"Failure", " ", "654321"));
}
public AppData getAppData(long id){
return appdatas.get(id);
}
Instead of user entering http://localhost:8080/gni/webapi/appdata/1 for the result
{
"id": 1,
"message": " ",
"status": "Success",
"token": "123456"
}
I hope that I can receive the user input with @POST and JSON format. I have tried the following code but not working.
@POST
@Path("/{appdataid}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public AppData getAppData(@PathParam("appdataid")long appdataid){
return ads.getAppData(appdataid);
}
Thanks for everyone that willing to help me.