Reputation: 21971
I cant seem to post JSON to my webservice but XML works fine:
@POST
@Consumes({"application/xml","application/json"})
public void addOrder(JAXBElement<OrderBean> order) {
System.out.println("COOL");
}
curl -v -X POST --data-binary "<orderBean><customer>test</customer></orderBean>" -H"Content-Type: application/xml" http://localhost:8080/webapp/rest/order
curl -v -X POST --data-binary "{"orderBean":{"customer":"test"}}" -H"Content-Type: application/json" http://localhost:8080/webapp/rest/order
I get the following error with JSON:
java.lang.Error: Error: could not match input
at com.sun.jersey.json.impl.reader.JsonLexer.zzScanError(JsonLexer.java:491)
Any help would be greatly appreciated.
Upvotes: 1
Views: 2401
Reputation: 21976
When your OrderBean
is properly annotated with any @XmlXXX
, you don't have to wrap it with JAXBElement<>
@POST
@Consumes(...)
public void addOrder(final OrderBean order) {
}
And you should send exactly the same JSON string Jersey can parse.
That means you should send exactly the same structure of JSON string that the Jersey prints
Please see
http://jersey.java.net/nonav/documentation/latest/json.html#d4e949
and
Print Jersey JSON in Unit Testing
Upvotes: 1