Restlet中的自定义JSON响应

我的应用程序具有一个REST资源,该资源返回一个Application对象

public class JeeApplicationsServerResource extends BaseServerResource
    implements ApplicationsResource {
  @Override
  public Application createApp(Application application) {
    if(!exists(application)) {
        return createApp(); // returns 
    } else {
        setStatus(Status.CLIENT_ERROR_BAD_REQUEST,appName + " already exists"); // <-- this is the issue
        return null;
    }
  }
}

问题是当错误为400时该资源应返回的响应应为:

{
  "response" : {
     "error" : "alpha already exists","code" : 400
  }
}

不是这个:

{
        "org.restlet.engine.application.StatusInfo": {
            "code": 400,"description": "alpha already exists","homeRef": "/","reasonPhrase": "Bad Request","uri": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1"
        }
    }

当资源的返回类型不是Representation时,Restlet中有没有办法做到这一点?

qq179091057 回答:Restlet中的自定义JSON响应

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3150009.html

大家都在问