0

So i have an ajax request, the content is a JSON string.

on the server side i have the following:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/test")
public Response test(String s) {
    Gson gson = new Gson(); 
    myBean obj = gson.fromJson(s, myBean.class);
    System.out.println(obj.getTimestemp() +" " + obj.getData().getItemCountryLocaion());
    return Response.ok().entity("ok").build();
}

the above code is working just find and i'm able to retrieve the data.

while trying to use the same ajax call and changing the server code to this:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/test")
public Response test(myBean s) {
    System.out.println(s.getTimestemp() +" " + s.getData().getItemCountryLocaion());
    return Response.ok().entity("ok").build();
}

I'm getting 415 status code as a response.

myBean class has @XmlRootElement annotation.

what did i do wrong?

USer22999299
  • 5,284
  • 9
  • 46
  • 78
  • 1
    Along with the duplicate, you may find the parts of [this answer](http://stackoverflow.com/a/31991892/2587435) informative – Paul Samsotha Aug 15 '15 at 07:56
  • @peeskillet i had everything as you said in your answer, the only thing that was missing is the Jackson JAXRS JSON 2.6.1, but after i added it still the same thing.. – USer22999299 Aug 15 '15 at 08:11
  • If you are basing off the answer in the linked comment, you still need to register the provider. If you are going off the duplicate, and you have the `jersey-media-json-jackson` dependency, then it should work out the box. If you are not using Maven, there is a link at the very bottom of the answer that points to the downloads you need. If you completely read the comment link, you will have noticed something about "implementation specific wrappers" around Jackson. The `jersey-media-json-jackson` is such a wrapper for Jersey, that registers the provider for you. So take your pick – Paul Samsotha Aug 15 '15 at 08:14

0 Answers0