I am creating a Jersey web service with dropwizard. The client is using JsonP
for cross domain ajax messages.
I got a resource method which looks like this:
@Path("/addUser")
@GET
@UnitOfWork
public String registerPortalUser(@Context HttpServletRequest req, @QueryParam("callback") String callback, @QueryParam("thedata") MyClass recordData) throws Throwable
{ .. }
I get the callback parameter as I expect, but instead of receiving a single Json string which is supposed to be injected to the MyClass
member, I get many parameters which are all the MyClass member names and its values. Meaning, instead of receiving everything as a single Json string, I get all the members apart.
What can cause this?
The issue was with the client. The client sent a json like this:
var thedata =
{
member1 = "value1",
member2 = "value2"
}
What solved it was sending it like this:
var thedata=
[ thedata:
{
member1 = "value1",
member2 = "value2"
}
]
After changing it, Jersey recognized it as the requested parameter
You're apparently sending a null MyClass object to the server. Your client code might look like
MyClass myC = new MyClass();
//populate MyClass fields
WebTarget target = client.target(UriBuilder.fromUri("http://localhost:8088/YourWebApp").build());
String res =(String) target.path("addUser").queryParam("thedata", myC).request().accept(MediaType.TEXT_PLAIN).get(String.class);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.