0

I am not able to read json data in post. So far I have been successful is reading string data in get method. Now i am working on POST where I am sending following JSON in body :

{"name": "myname","address":"myaddress"}

I am also sending content-type : application/json header information in the request.

I have downloaded jersey moxy jar and corresponding dependencies. My model class is as following :

@XmlRootElement
public class Mymodel{
@XMLElement
public String name;
@XMLElement
public String address;
}

following is the extract of the resource method

@POST
@Consumes(MediaType.Application_JSON)
public Resource mymethod(Mymodel mode){
System.out.println(mode.name);
}

Am i missing something ? Error I am getting is that media type is not supported(415 Unsupported Media Type). I don't have anything related to json in the web.xml.

As i mentioned in my post above ,I am using jersey moxy jar which actually supports json application type in jersey. So my understanding is that as suggested adding "jersey-media-json-jackson" jar will not add any value, or I need both jackson and moxy jar ?

tec
  • 41
  • 9
  • 3
    Have a look at [this](http://stackoverflow.com/q/30692221/2587435) – Paul Samsotha Dec 17 '15 at 03:53
  • @peeskillet: Thanks a lot for help. Please see my updated question, I am already using moxy jar for that purpose, do i still need jackson jar ? – tec Dec 17 '15 at 04:32
  • No. Add an `ExceptionMapper` and print the stacktrace. If it's a problem with the MOXy deserialization, you should see an exception. – Paul Samsotha Dec 17 '15 at 04:36
  • 1
    **To closers:** Please don't close as a duplicate (this is not a duplicate as the OP already has a provider) – Paul Samsotha Dec 17 '15 at 04:37
  • You can also try and add `@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)` or if that doesn't work `@XmlAccessorType(XmlAccessType.FIELD)` on top of `Mymodel` – Paul Samsotha Dec 17 '15 at 04:39
  • You only downloaded one MOXy jar? Nothing else with it? – Paul Samsotha Dec 17 '15 at 11:01
  • Hello All, Problem is solved, i do not know the exact reason , but i had two jars in my classpath, gson and moxy, i removed gson from my class path and it started working, i saw apache logs, there was nothing mentioned there, but thanks @peeskillet – tec Dec 18 '15 at 05:18

0 Answers0