小编Hei*_*erg的帖子

我应该如何在Jersey 2中返回JSON响应

我在尝试使用Jersey 2中的JSON对象返回Response时遇到问题.

以下是代码段:

        import javax.ws.rs.GET;
        import javax.ws.rs.Path;
        import javax.ws.rs.Produces;
        import javax.ws.rs.core.MediaType;
        import javax.ws.rs.core.Response;
        import javax.ws.rs.core.Response.Status;
        import org.codehaus.jettison.json.JSONObject;

        @Path("/message")
        public class HelloWorld {

          @Path("/getJson")
          @GET
          @Produces(MediaType.APPLICATION_JSON)
          public Response getJSON() {
            JSONObject object = null;
            Response response = null;
            try {
              object = new JSONObject();
              object.put("Name", "Bryan");
              object.put("Age", "27");
              response = Response.status(Status.OK).entity(object).build();
            } catch (Exception e) {
              System.out.println("error=" + e.getMessage());
            }
            return response;
          }
        }
Run Code Online (Sandbox Code Playgroud)

我得到以下异常:

 No serializer found for class org.codehaus.jettison.json.JSONObject and no  properties discovered to create BeanSerializer (to avoid exception, …
Run Code Online (Sandbox Code Playgroud)

jersey-2.0

3
推荐指数
1
解决办法
9277
查看次数

如何将double值转换为大整数或长整数

需要将double值转换为大整数或长整数.尝试使用大整数但转换后的值与原始值不同.

double doub = 123456789123456789123456789d;
BigDecimal bd = BigDecimal.valueOf(doub);
System.out.println("value=="+bd.toBigInteger());

value==123456789123456790000000000

Expected output: 123456789123456789123456789
Run Code Online (Sandbox Code Playgroud)

java double biginteger

0
推荐指数
1
解决办法
154
查看次数

标签 统计

biginteger ×1

double ×1

java ×1

jersey-2.0 ×1