返回Jersey响应与自定义POJO类对象

时间:2017-03-07 11:23:04

标签: java jax-rs pojo jersey-1.0

我很难确定哪种方式更好,在球衣中我们可以返回Response对象(jax-rs)以及自定义的pojo类对象。我不知道哪种方式更好,为什么有人建议?请注意两种情况下的返回类型。这是我的两个案例。

案例1:

@POST
    @Path("/authentication")
    public AuthenticationResponse authenticate(@NotNull FITransXTRequest objFITransXTRequest) {
        logger.debug("## entering authenticate method");

        System.out.println(objFITransXTRequest);
        AuthenticationResponse objAuthResponse = new AuthenticationResponse();
        JsonObject objResult = objAuthentication.authenticate(objFITransXTRequest);
        System.out.println(objFITransXTRequest);
        if (objResult != null) {
            objAuthResponse.setStan(objResult.get("stan").getAsString());
            objAuthResponse.setErrorMessage(objResult.get("responseMsg").getAsString());
            objAuthResponse.setStatus(objResult.get("responseCode").getAsString());
            objAuthResponse.setUidNumber(objResult.get("uidNumber").getAsString());
            objAuthResponse.setRrn(objResult.get("rrn").getAsString());
            objAuthResponse.setRdt(objFITransXTRequest.getDt());
        }
        return objAuthResponse;
    } 

案例2:

 @POST
    @Path("/authentication")
    public Response authenticate(FITransXTRequest objFITransXTRequest) {
        AuthenticationResponse objAuthResponse = new AuthenticationResponse();
        JsonObject objResult = objAuthentication.authenticate(objFITransXTRequest);
        System.out.println(objFITransXTRequest);
        if (objResult != null) {
objAuthResponse.setStan(objResult.get("stan").getAsString());
            objAuthResponse.setErrorMessage(objResult.get("responseMsg").getAsString());
            objAuthResponse.setStatus(objResult.get("responseCode").getAsString());
            objAuthResponse.setUidNumber(objResult.get("uidNumber").getAsString());
            objAuthResponse.setRrn(objResult.get("rrn").getAsString());
            objAuthResponse.setRdt(objFITransXTRequest.getDt());
        }
        return Response.ok( objAuthentication.authenticate(objFITransXTRequest)).build();
    } 

注意:我只想返回一个200 ok的状态代码。

0 个答案:

没有答案