JSON.toJSONString()null值转“”
public static void main(String[] s) {
CybWmsCommoditiesVo cybWmsCommoditiesVo = new CybWmsCommoditiesVo();
CybItemVo cybItemVo = new CybItemVo();
cybItemVo.setStockUnit("2134");
cybWmsCommoditiesVo.setSupplierCode("24234");
cybWmsCommoditiesVo.setItem(cybItemVo); String requestBody = JSON.toJSONString(cybWmsCommoditiesVo, filter);
System.out.print(requestBody);
}
private static ValueFilter filter = new ValueFilter() {
@Override
public Object process(Object obj, String s, Object v) {
if (v == null)
return "";
return v;
}
};
JSON.toJSONString()方法默认会将对象中的空字符串忽略.
加上这个过滤器后,所有的null值和""值都会被转换成""值输出到字符串中.
#############
private SerializerFeature[] features = new SerializerFeature[] {
WriteMapNullValue, WriteNullNumberAsZero, WriteNullListAsEmpty,
WriteNullStringAsEmpty,WriteDateUseDateFormat
};
return JSON.toJSONString(page, features);
JSON.toJSONString()null值转“”的更多相关文章
- springmvc 1.接受日期类型的参数 2.后台返回json串的格式处理(返回json串null值处理为"")
springmvc中的配置: <bean id="dateConvert" class="com.iomp.util.DateConvert"/> ...
- SpringBoot项目中处理返回json的null值
在后端数据接口项目开发中,经常遇到返回的数据中有null值,导致前端需要进行判断处理,否则容易出现undefined的情况,如何便捷的将null值转换为空字符串? 以SpringBoot项目为例,SS ...
- jackson 转json. 过滤null值
@Test public void tttttt() throws JsonGenerationException, JsonMappingException, IOException { Objec ...
- Newtonsoft.Json.dll序列化为json,null值自动过滤
var jSetting = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore}; var json = ...
- spring boot 返回json字符串 null值转空字符串
@Configuration public class JacksonConfig { @Bean @Primary @ConditionalOnMissingBean(ObjectMapper.cl ...
- Map 转 json格式 保留null值的解决办法
Map 转 json格式 保留null值的解决办法 开发中遇到将map数据转json格式,然后map中含null值的键值对都被转没了,所以记录一下,以下是解决方法 使用fastJson进行转换 imp ...
- JSON序列化自己主动过滤NULL值
使用Newtonsoft.Json.dll 序列化为json时主动将NULL值过滤掉.详细做法: var jSetting = new JsonSerializerSettings {NullValu ...
- 大数据学习day28-----hive03------1. null值处理,子串,拼接,类型转换 2.行转列,列转行 3. 窗口函数(over,lead,lag等函数) 4.rank(行号函数)5. json解析函数 6.jdbc连接hive,企业级调优
1. null值处理,子串,拼接,类型转换 (1) 空字段赋值(null值处理) 当表中的某个字段为null时,比如奖金,当你要统计一个人的总工资时,字段为null的值就无法处理,这个时候就可以使用N ...
- 使用fastjson,gson解析null值的时候键保留
由于业务需求...所以查阅资料,总结如下: 使用gson实现方法:只需要把new Gson()改为: new GsonBuilder().serializeNulls().create(); 就可以了 ...
随机推荐
- c++简单String类实现
#include <iostream> #include <string> using namespace std; class String { public: String ...
- upc组队赛7 Star in Parentheses
Star in Parentheses 题目描述 You are given a string S, which is balanced parentheses with a star symbol ...
- jQuery选择器中空格的问题再探究
jQuery选择器的空格问题,看似很小,但是差之毫厘谬以千里,让人很是恼火,<锋利的jQuery>书中有个经典的例子,我这里也拷贝下来,再加点自己的想法 <html> < ...
- span 设置inline-block 写文字的span错位
写一个如下图这样排版 设置几个span为inline-block 中间的span写了文字的span错位了 解决方案 给span添加 vertical-align: top
- IDEA如何import一个新的项目
首先解决依赖问题:打开pom.xml 2.打开File->setting 将里面的User setting file位置找到,放上settings.xml(注意要打开,将第一行位置改一下) 3. ...
- 如何在web项目中配置Spring的Ioc容器
在web项目中配置Spring的Ioc容器其实就是创建web应用的上下文(WebApplicationContext) 自定义要使用的IoC容器而不使用默认的XmlApplicationContext ...
- C语言交换两个数的值
#include<stdio.h> int main() { //交换两个数的值 // 方法一 可读性最好 ; ; int temp ; temp = a; a = b; b = temp ...
- 【记录】Nginx错误could not build the server_names_hash you should increase server_names_hash_bucket_size: 32
今天遇到这个错误,现记录下解决方案: 在nginx的配置文件的http段中增加如下配置: server_names_hash_bucket_size 64; 下面是nginx官方文档解释: 如果定义了 ...
- 2018-2-13-win10-安装Mpi
title author date CreateTime categories win10 安装Mpi lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23: ...
- teb教程4
障碍物避障以及机器人足迹模型 简介:障碍物避障的实现,以及必要参数的设置对于机器人足迹模型和其对应的影响 1.障碍物避障是怎样工作的 1.1 惩罚项 障碍物避障作为整个路径优化的一部分.显然,优化是找 ...