首页
App
&
Coffee
文档
项目
分享
反馈
俱乐部
登录
注册
请问大家,JFinal里面全局设置WriteMapNullValue怎么弄?
鱼跃人
2023-05-24 10:22
现在项目里面用FastJsonFactory,现在对象转JSON,如果对象的字段为空则不会返回给前端,我想全局设置一下序列化值为 null 的字段,怎么做呢
项目:
JFinal
1
评论区
杜福忠
2023-05-24 13:07
个人认为不如直接使用MixedJsonFactory 性能更高,配置一下就可以了:
public void configConstant(Constants me) {
me.setJsonFactory(new MixedJsonFactory());
}
官方提供了 MixedJson、MixedJsonFactory 实现,这个实现让转 json string 时使用 JFinalJson,反向转成对象则使用 FastJson。
https://jfinal.com/doc/12-2
必须Fast转字符串的话就继承FastJsonFactory和FastJson改一下返回值:
return JSON.toJSONString(object) 改为 :
return JSON.toJSONString(r, SerializerFeature.WriteMapNullValue);
就可以了
回复
风满楼
2023-05-24 14:43
看下这个满足嘛 https://jfinal.com/share/2344
回复
发送
我要反馈
赞助商
禅道 - 专业的项目管理软件
热门反馈
JFinal 社区 feedback 反馈栏目
jfinal模块化开发的best practice是怎么样的
eclipse有没有一个类似idea的黑色主题
BaseModel中定义的变量会在不同线程中冲突吗?
jfinal配置错误页面
Render类的render方法为什么会被自动执行?
jfinal做微服务和分布式架构,能否给点好的案例,或者好的方案,现在技术选型上面想做考究。
jfinal_club后台登录地址是什么?
jfinal官网怎么没有搜索功能?
renderJson方法返回页面时,long型数值别截取
扫码入社
public void configConstant(Constants me) {
me.setJsonFactory(new MixedJsonFactory());
}
官方提供了 MixedJson、MixedJsonFactory 实现,这个实现让转 json string 时使用 JFinalJson,反向转成对象则使用 FastJson。
https://jfinal.com/doc/12-2
必须Fast转字符串的话就继承FastJsonFactory和FastJson改一下返回值:
return JSON.toJSONString(object) 改为 :
return JSON.toJSONString(r, SerializerFeature.WriteMapNullValue);
就可以了