当前位置:网站首页>【伸手党福利】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输出即可。
边栏推荐
- Elk elegant management server log
- How do spark tasks of 10W workers run? (Distributed Computing)
- JUC learning
- pytorch训练深度学习网络设置cuda指定的GPU可见
- Chapter 03_ User and authority management
- Mybati SQL statement printing
- 数据库DDL(Data Definition Language,数据定义语言)知识点
- Gorilla/mux framework (RK boot): RPC error code design
- Promise中finally的用法
- Kmeans
猜你喜欢

Nacos

Avalanche problem and the use of sentinel

Best used trust automation script (shell)

服务器渲染技术jsp

Pyramid Scene Parsing Network【PSPNet】论文阅读

IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
![Pyramid scene parsing network [pspnet] thesis reading](/img/05/4645c8a595083479dee6835620335d.png)
Pyramid scene parsing network [pspnet] thesis reading

手把手带你了解一块电路板,从设计到制作(干货)

ASGNet论文和代码解读2

数据交换 JSON
随机推荐
Research on target recognition and tracking based on 3D laser point cloud
Best used trust automation script (shell)
雪崩问题以及sentinel的使用
Latest interface automation interview questions
File upload and download
So easy deploy program to server
10、Scanner.next() 无法读取空格/indexOf -1
Nacos
[nine day training] content III of the problem solution of leetcode question brushing Report
Basic concepts of database
gcc使用、Makefile总结
Avalanche problem and the use of sentinel
家居网购项目
Listener listener
Hal library setting STM32 interrupt
The best learning method in the world: Feynman learning method
[us match preparation] complete introduction to word editing formula
torch.histc
Pathmeasure implements loading animation
Subnet division and subnet summary