能不能将返回的json格式下的每一个字段都转换为String类型的.
例如:对象的字段sex为int,值为0或1,在返回的时候能否为{"sex":0} ==> {"sex":"0"}
8 回复
写倒是能写
@Test
public void test_json_all_string() throws IOException {
StringWriter sw = new StringWriter();
new JsonRenderImpl(sw, JsonFormat.full()){
public void render(Object value) throws IOException {
if (value != null && value instanceof Number) {
getWriter().write(Json.toJson(value.toString()));
} else {
super.render(value);
}
}
}.render(new NutMap("age", 1));
System.out.println(sw.getBuffer().toString());
}
输出
{
"age": "1"
}
添加回复
请先登陆