import com.alibaba.fastjson.*; import com.alibaba.fastjson.serializer.*; public class JSONFilter { public static class MyValueFilter implements ValueFilter { public Object process(Object object, String name, Object value) { if (value != null && value instanceof Double) { String str = value.toString(); if (str.endsWith(".0")) str = str.substring(0, str.length() - 2); else if (str.endsWith(".00")) str = str.substring(0, str.length() - 3); return str; } return value; } } public static void main(String[] args) { JSONObject json = new JSONObject(true); json.put("double", 1.0); System.out.println(JSON.toJSONString(json)); System.out.println(JSON.toJSONString(json, new MyValueFilter())); System.out.println(json.get("double").getClass().getName()); } }