I have been through this link. but this did not helped me out.
I am using jersey lib v1.17.1. My jersey rest service:
@POST
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Path("/post1")
public ResponseBean post1(@QueryParam("param1")String param1)
{
return ResponseFactory.createResponse(param1, "TEST", "TEST", null, true);
}
url is: /test/post1
My ajax call:
var d = {"param1":"just a dummy data"};
$.ajax({
type : "POST",
url : "http://localhost:7070/scl/rs/test/post1",
contentType :"application/json; charSet=UTF-8",
data : d,
dataType : "json"
})
.done(function(data){
console.log(data);
})
.fail(function(data){
console.log(data);
});
It hits to my rest service but as param1
I am alway getting null value. The alternate solution is to add JavaBean with @XMLRootElement
which will marshal/unmarshal the java object to json and vice versa, but I do not want to use this.
Is there any way to post data and receive it using appropriate annotation like @QueryParam
or something like that ?
Please help