我做了一个rest控制器,它返回json。我从数据库中获取这些数据,使用setter getterMap到java类中。
{
"example": null,
"this": null,
"is": null,
"only": null,
"example": null,
"foo": null,
"bar": null,
"blabla": null,
"lala": null
}
这是因为数据库中的数据不存在。但我希望数据是这样的:
{
"example": "" ,
"this": "",
"is": "",
"only": "",
"example": "",
"foo": "",
"bar": "",
"blabla": "",
"lala": ""
}
我有超过100个字段。所以我认为在每个变量中使用if else是不好的。
3条答案
按热度按时间roqulrg31#
您可以覆盖默认的
ObjectMapper
(由Sping Boot 自动配置提供),并全局配置格式以用于String
类型的属性。t9eec4r02#
在哪里
qltillow3#
你可以通过处理json字符串更容易地解决这个问题: