我在尝试使用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) 需要将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)