Play使用GSON构建JSON字符串。如果您的字段是一种特定的对象类型,则可以通过为该类型提供自定义的序列化来轻松完成此操作。在这里查看文档
http://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-
and-Deserializ
但是,例如,如果它是一个Integer类,而您想以一种方式工作,而又以另一种方式工作,则您可能会遇到一些困难。
例
GsonBuilder gson = new GsonBuilder();gson.registerTypeAdapter(SpecificClass.class, new MySerializer());private class MySerializer implements JsonSerializer<DateTime> { public JsonElement serialize(SpecificClass src, Type typeOfSrc, JsonSerializationContext context) { String res = "special format of specificClass" return new JsonPrimitive(res); }}


