如何使javax.ws.rs.core.Response返回特定字段

时间:2018-10-12 17:14:55

标签: rest web-services jax-rs spring-restcontroller

我正在编写一个基于Spring的Restful Web服务。我返回javax.ws.rs.core.Response作为响应。我正在使用ResponseBuilder创建响应。

Response.status(200).entity(response).build();

当我使用邮递员验证响应时,可以看到如下响应对象

{
    "context": {
        "headers": {},
        "entity": {
            "status": "Success",
            "message": "Ok"
        },
        "entityType": "com.sample.response.SampleResponse",
        "entityAnnotations": [],
        "entityStream": {
            "closed": false,
            "committed": false
        },
        "length": -1,
        "language": null,
        "location": null,
        "date": null,
        "lastModified": null,
        "mediaType": null,
        "allowedMethods": [],
        "committed": false,
        "entityClass": "com.sample.response.SampleResponse",
        "lengthLong": -1,
        "responseCookies": {},
        "acceptableLanguages": [
            "*"
        ],
        "requestCookies": {},
        "acceptableMediaTypes": [
            {
                "type": "*",
                "subtype": "*",
                "parameters": {},
                "quality": 1000,
                "wildcardSubtype": true,
                "wildcardType": true
            }
        ],
        "stringHeaders": {},
        "links": [],
        "entityTag": null
    },
    "status": 500,
    "length": -1,
    "language": null,
    "location": null,
    "date": null,
    "lastModified": null,
    "metadata": {},
    "mediaType": null,
    "cookies": {},
    "entity": {
        "status": "Success",
        "message": "Ok"
    },
    "allowedMethods": [],
    "stringHeaders": {},
    "links": [],
    "entityTag": null,
    "statusInfo": "INTERNAL_SERVER_ERROR",
    "headers": {}
}

我只想查看我的响应(即SampleResponse)对象字段。有人可以帮我吗?

我的API端点

 @RequestMapping(value = "/register", method = RequestMethod.POST)
public Response register(@RequestBody RegisterDto register){
    return userService.registerUser(register.getMobile());
}

我返回的回复是

sampleResponse response = new SampleResponse();
 return Response.status(200).entity(response).build();

0 个答案:

没有答案