2018-11-13   09:21:44

Gson的两种实例化方式:

1: 使用new Gson(); 普通实例化方式,不能配置定制化选项

Gson gson = new Gson(); 

2: 通过GsonBuilder 可以配置多种选项

Gson gson = new GsonBuilder().setLenient()// json宽松  
        .enableComplexMapKeySerialization()//支持Map的key为复杂对象的形式  
        .serializeNulls() //智能null,支持输出值为null的属性
        .setPrettyPrinting()//格式化输出(序列化)
        .setDateFormat("yyyy-MM-dd HH:mm:ss") //序列化日期格式化输出 
        .excludeFieldsWithoutExposeAnnotation() //不序列化与反序列化没有@Expose标注的字段

        .disableHtmlEscaping() //默认是Gson把HTML转义的  
        .create();

 

相关文章:

  • 2021-11-16
  • 2021-06-06
  • 2022-12-23
  • 2021-05-12
  • 2022-01-02
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2021-11-05
  • 2021-10-09
  • 2021-08-01
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案