设置时间转换格式
JSON.registerObjectMarshaller(
Date) {
return it?.format(
"yyyy-MM-dd HH:mm:ss")
}
输出pojo的指定字段
JSON
.registerObjectMarshaller(User) {
user ->
return [
id: user
.id,
username: user
.username
]
}
输出json
render obj as JSON
JSON json = new JSON(obj) render json
使用 new JSON方式 设置只包含或不包含的字段
JSON json =
new JSON(
map)
json.setIncludes(User.
class, [
"id",
"address",
"phone",
"username"])
json.setIncludes(Role.
class, [
"name"])
json.setExcludes(Img.
class, [
"memo"])
render json
以上内容源自互联网,自己做的简单总结,记录一下。