Robert Hume Robert Hume - 2 months ago 4x
Java Question

what's wrong with my simple JSON JAX-RS web service?

I have a simple web service written with Apache Wink 1.0, I want to receive and return JSON data.

According the Wink docs, this should work ...

public JSONObject postJSON(JSONObject requestJSON) {
JSONObject jobj = new JSONObject();
return jobj;

... but I see this error when I try to hit the web service ...

org.apache.wink.server.internal.handlers.PopulateResponseMediaTypeHandler -
Content-Type not specified via Response object or via @Produces annotation
so automatically setting via generic-type compatible MessageBodyWriter providers

... any advice or suggestions are greatly appreciated!



Usage of JSONObject is a little bit strange. Easier and more flexible approach:

public MyDto postJSON(MyDto dto) {
  //do something
  MyDto md = new MyDto();
  return md;

public class MyDto {
  private String f1;
  private int f2;

JAX-RS would serialize MyDto do JSON. In fact, even cleaner approach is to return Response object

public Response postJSON(MyDto dto) {
    //do something
    MyDto md = new MyDto();
    return Response.ok(md);