当前位置:网站首页>【伸手党福利】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输出即可。
边栏推荐
- EtherCAT原理概述
- pytorch训练深度学习网络设置cuda指定的GPU可见
- Pathmeasure implements loading animation
- 不用加减乘除实现加法
- File upload and download
- Md5sum operation
- [us match preparation] complete introduction to word editing formula
- 实现pow(x,n)函数
- [深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
- Take you through a circuit board, from design to production (dry goods)
猜你喜欢

伺服第二编码器数值链接到倍福PLC的NC虚拟轴做显示

E15 solution for cx5120 controlling Huichuan is620n servo error

过滤器 Filter

pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear

数据交换 JSON

8 pits of redis distributed lock

Hal library setting STM32 interrupt

A few lines of transaction codes cost me 160000 yuan

倍福TwinCAT3 Ads相关错误详细列表

Nacos
随机推荐
torch.histc
ASGNet论文和代码解读2
FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)
C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
Redis 教程
Pyramid scene parsing network [pspnet] thesis reading
终极套娃 2.0 | 云原生交付的封装
Error accessing URL 404
Subnet division and subnet summary
【读书笔记】《文案变现》——写出有效文案的四个黄金步骤
Leetcode 1818 absolute value, sorting, dichotomy, maximum value
[us match preparation] complete introduction to word editing formula
How to use hybrid format to output ISO files? isohybrid:command not found
[nine day training] content III of the problem solution of leetcode question brushing Report
Common interview questions for performance test
Detailed explanation of ES6 deconstruction grammar
Best used trust automation script (shell)
Hal library setting STM32 interrupt
Nacos
Latest interface automation interview questions