0
我有以下方法返回整数(原始类型):如何作为响应JSON
public class sum {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes("application/json")
public responseObject sumOfTwo(@QueryParam("a") int a, @QueryParam("b") int b) {
return new responseObject(a+b);
}
}
@XmlRootElement
class responseObject{
public int res;
public responseObject(int res){
this.res = res;
}
public responseObject(){
//default C'tor
}
public int getRes(){
return this.res;
}
}
这将返回{"res":"value of a+b"}
在引号值。我希望它作为一个整数返回值,不用引号,但我把它作为一个字符串。我如何序列化/反序列化它只输出一个整数?
整数,而不是INT ins't影响。 我使用默认的Json提供程序,现在尝试与Jackson合作。 – ohadsas