简体   繁体   English

用杰克逊响应json Web服务

[英]response json web services with jackson

Hi i have my web services with Jersey and i use jackson for the generating JSON object i have for example my resource TESTS with set/get method: 嗨,我在Jersey拥有我的Web服务,我使用jackson生成JSON对象,例如,我的资源TESTS具有set / get方法:

public class Tests {

    private String name;

    private String result;

    private String credit;

}

my api: 我的api:

@Path("/getTests")
    @GET
    @ManagedAsync
    @Produces(MediaType.APPLICATION_JSON)
    public void listsTests(@Suspended final AsyncResponse response) {

       ListenableFuture<Collection<Esame>> listTests = service
                .getTestsInterfaceAsync();


        Futures.addCallback(listTests, new FutureCallback<Collection<Tests>>() {

            public void onSuccess(Collection<Tests> tests) {
                response.resume(tests);
            }

            public void onFailure(Throwable thrown) {
                response.resume(thrown);
            }
        });

and if i call my api works well, i have this JSON: 如果我调用我的api效果很好,则可以使用以下JSON:

{
 name=something
 result=6
 credit=12
}

{
 name=something
 result=6
 credit=12
}

{
 name=something
 result=6
 credit=12
}

{
 name=something
 result=6
 credit=12
}

now my question, if i want to add the status of response? 现在是我的问题,是否要添加回复状态? for example: 例如:

{
 status=200
}
{
 name=something
 result=6
 credit=12
}

i must add Object status in a Tests class?..but in this case the result will be: 我必须在Tests类中添加对象状态?。但是在这种情况下,结果将是:

  {
     status=200
     name=something
     result=6
     credit=12
    }
 {
     status=200
     name=something
     result=6
     credit=12
    }

try something 尝试一些

public class Result{
    private Integer status;
    private List<Tests> tests;

    // getters and setters 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM