我有以下的球衣资源,新泽西州已经配置为使用杰克逊自动JSON-POJO转换:为什么杰克逊串行数字字段为字符串?
@Path("/test")
public class TestResource {
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public TestResponse testGet(final TestRequest req) {
final TestResponse response = new TestResponse();
response.x = req.x + 1;
return response;
}
@XmlRootElement
public static class TestRequest {
public int x;
}
@XmlRootElement
public static class TestResponse {
public int x;
}
}
我把这个用:
{"x":5}
,并获得响应:
{"x":"6"}
但是为什么这里的值的字符串,在TestResponse X字段是一个int?
一切都被默认序列化到字符串。我不知道为什么这是客户的问题。 – smk 2012-02-29 17:21:33
嗯,奇怪 - 我怎样才能改变这种行为? – sanity 2012-02-29 18:27:52
你解决这个问题? – 2015-10-08 14:08:08