当前位置:网站首页>【伸手党福利】JSONObject转String保留空字段
【伸手党福利】JSONObject转String保留空字段
2022-07-01 03:17:00 【三个人工作室】
同样解决的问题:
Redis当中保留空字段取出
JSONObject转为String型时保留空字段
将String型转为JSONObject型时保留空字段
原因
Object型和JSONObject型转换为String型的时候,空字段会被自动忽略。
解决方式
使用class实体类作为模板进行输出,将String型转为实体类型
需要引入hutool
import cn.hutool.json.JSONUtil;
...
UserInfo userinfo = JSONUtil.toBean(String.valueOf(redisUtil.get(UserToken)),UserInfo.class)
UserInfo.java
import lombok.Data;
//输出用户信息的虚拟实体类
@Data
public class UserInfo {
private String id;
private String username;
private String realname;
}
然后通过实体类进行get和set输出即可。
边栏推荐
- Subnet division and subnet summary
- 雪崩问题以及sentinel的使用
- 10、Scanner.next() 无法读取空格/indexOf -1
- Force buckle - sum of two numbers
- Md5sum operation
- FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
- [reading notes] copywriting realization -- four golden steps for writing effective copywriting
- Common interview questions for performance test
- 家居网购项目
- [小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation
猜你喜欢
随机推荐
GCC usage, makefile summary
Redis tutorial
IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
5、【WebGIS实战】软件操作篇——服务发布及权限管理
过滤器 Filter
终极套娃 2.0 | 云原生交付的封装
leetcode 1818 绝对值,排序,二分法,最大值
leetcode 1482 猜猜看啊,这道题目怎么二分?
Latest interface automation interview questions
串口接收数据方案设计
About the application of MySQL
Research on target recognition and tracking based on 3D laser point cloud
家居网购项目
倍福TwinCAT3 Ads相关错误详细列表
JUC learning
Keil5中如何做到 0 Error(s), 0 Warning(s).
不用加减乘除实现加法
So easy deploy program to server
Druid monitoring statistics source
Edge Drawing: A combined real-time edge and segment detector 翻译