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值转“”的更多相关文章

  1. springmvc 1.接受日期类型的参数 2.后台返回json串的格式处理(返回json串null值处理为"")

    springmvc中的配置: <bean id="dateConvert" class="com.iomp.util.DateConvert"/> ...

  2. SpringBoot项目中处理返回json的null值

    在后端数据接口项目开发中,经常遇到返回的数据中有null值,导致前端需要进行判断处理,否则容易出现undefined的情况,如何便捷的将null值转换为空字符串? 以SpringBoot项目为例,SS ...

  3. jackson 转json. 过滤null值

    @Test public void tttttt() throws JsonGenerationException, JsonMappingException, IOException { Objec ...

  4. Newtonsoft.Json.dll序列化为json,null值自动过滤

    var jSetting = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore}; var json = ...

  5. spring boot 返回json字符串 null值转空字符串

    @Configuration public class JacksonConfig { @Bean @Primary @ConditionalOnMissingBean(ObjectMapper.cl ...

  6. Map 转 json格式 保留null值的解决办法

    Map 转 json格式 保留null值的解决办法 开发中遇到将map数据转json格式,然后map中含null值的键值对都被转没了,所以记录一下,以下是解决方法 使用fastJson进行转换 imp ...

  7. JSON序列化自己主动过滤NULL值

    使用Newtonsoft.Json.dll 序列化为json时主动将NULL值过滤掉.详细做法: var jSetting = new JsonSerializerSettings {NullValu ...

  8. 大数据学习day28-----hive03------1. null值处理,子串,拼接,类型转换 2.行转列,列转行 3. 窗口函数(over,lead,lag等函数) 4.rank(行号函数)5. json解析函数 6.jdbc连接hive,企业级调优

    1. null值处理,子串,拼接,类型转换 (1) 空字段赋值(null值处理) 当表中的某个字段为null时,比如奖金,当你要统计一个人的总工资时,字段为null的值就无法处理,这个时候就可以使用N ...

  9. 使用fastjson,gson解析null值的时候键保留

    由于业务需求...所以查阅资料,总结如下: 使用gson实现方法:只需要把new Gson()改为: new GsonBuilder().serializeNulls().create(); 就可以了 ...

随机推荐

  1. 2015 ACM-ICPC 亚洲区上海站 A - An Easy Physics Problem (计算几何)

    题目链接:HDU 5572 Problem Description On an infinite smooth table, there's a big round fixed cylinder an ...

  2. 基于MFC的Media Player播放器制作的SetTimer函数介绍

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. SetTimer是一种API函数,位于user32.dll中.你想每隔一段时间执行一件事的的时候,你可以使用它. 使用定时器的方法比 较简 ...

  3. Spring整合Hibernate报错:annotatedClasses is not writable or has an invalid setter method

    Spring 整合Hibernate时报错: org.springframework.beans.factory.BeanCreationException: Error creating bean ...

  4. docker运行我们的容器

    docker images docker pull nginx 运行 docker images 查看Nginx镜像是否获取成功,若为如下所示即为获取成功: docker run -p 8080:80 ...

  5. call和apply实现的继承

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. 2019-8-28-WPF-开发

    title author date CreateTime categories WPF 开发 lindexi 2019-8-28 11:3:39 +0800 2018-2-13 17:23:3 +08 ...

  7. MySQL练习题--sqlzoo刷题

    首先查看world表的字段: name continent area population gdp capital tld flag SELECT * FROM world: 2.显示人口至少为2亿的 ...

  8. Codeforces Round #552:G. Minimum Possible LCM

    官方题解是时间复杂度为O(nd)的.这里给出一个简单实现但是时间复杂度为O(NlogN) (N=1e7) 因为 a*b/gcd(a,b)=lcm(a,b) 所以我们可以枚举每一个因子,然后找到存在这个 ...

  9. 【CSS】三栏布局的经典实现

    要求:自适应宽度,左右两栏固定宽度,中间栏优先加载: <!DOCTYPE html> <html> <head> <title>layout</t ...

  10. 一篇不一样的Android屏幕适配具体做法(原创)

    转载请注明出处(http://www.cnblogs.com/weizhxa/p/7568090.html ) 有不正确,还请大家留言修正! 1.何谓屏幕适配:在任何设备上看起来布局都是近似的,细分也 ...