SerialFeature
来源:互联网 发布:帕拉卡斯头骨 知乎 编辑:程序博客网 时间:2024/05/04 05:02
转载于:http://code.alibabatech.com/wiki/display/FastJSON/Serial+Features
Fastjson序列化时,可以指定序列化的特性,以满足不同的序列化需求。
SerialFeature类的定义
package
com.alibaba.fastjson.serializer;
public
enum
SerializerFeature {
QuoteFieldNames, UseSingleQuotes, WriteMapNullValue, WriteEnumUsingToString, UseISO8601DateFormat, SkipTransientField
}
使用举例
Date date =
new
Date(1308841916550L);
// 缺省输出
System.out.println(JSON.toJSONString(date));
// 1308841916550
// 使用特性 UseISO8601DateFormat
// "2011-06-23T23:11:56.550"
System.out.println(JSON.toJSONString(date, SerializerFeature.UseISO8601DateFormat));
// 组合两个Feature(UseISO8601DateFormat和UseSingleQuotes)输出日期
SerializerFeature[] features = {SerializerFeature.UseISO8601DateFormat, SerializerFeature.UseSingleQuotes };
System.out.println(JSON.toJSONString(date, features));
// '2011-06-23T23:11:56.550'
详细说明表格
QuoteFieldNames Feature Enabled:
{
"id"
:
123
,
"name"
:
"张三"
,
"age"
:
23
}
QuoteFieldNames Feature Disabled:
{id:
123
, name:
"张三"
, age:
23
}
UseSingleQuotes Feature Enabled:
{
'id'
:
123
,
'name'
:
'张三'
,
'age'
:
23
}
UseSingleQuotes Feature Disabled:
{
"id"
:
123
,
"name"
:
"张三"
,
"age"
:
23
}
WriteMapNullValue Feature Enabled:
{
'id'
:
123
,
'name'
:
'张三'
,
'age'
:
23
, birthday :
null
}
WriteMapNullValue Feature Disabled:
{
"id"
:
123
,
"name"
:
"张三"
,
"age"
:
23
}
public
static
enum
Type {
Big, Medium, Small
}
System.out.println(JSON.toJSONString(Type.Big));
// 0
System.out.println(JSON.toJSONString(Type.Medium));
// 1
System.out.println(JSON.toJSONString(Type.Small));
// 2
System.out.println(JSON.toJSONString(Type.Big, SerializerFeature.WriteEnumUsingToString));
// "Big"
System.out.println(JSON.toJSONString(Type.Medium, SerializerFeature.WriteEnumUsingToString));
// "Medium"
System.out.println(JSON.toJSONString(Type.Small, SerializerFeature.WriteEnumUsingToString));
// "Small"
Date date =
new
Date(1308841916550L);
System.out.println(JSON.toJSONString(date));
// 1308841916550
// "2011-06-23T23:11:56.550"
System.out.println(JSON.toJSONString(date, SerializerFeature.UseISO8601DateFormat));
- SerialFeature
- 头文件相互包含引起的错误(对类前置声明和包含头文件的理解 )
- Gaea个人计划预启动。。。
- Fastjson内幕
- Hibernate初级知识学习(1)
- 浅谈深度学习(Deep Learning)的基本思想和方法
- SerialFeature
- make与makefile项目管理实验 ---对“$^ $@ $<”参数的说明
- ios Mac下的SVN工具:Cornerstone与Versions和使用subversion管理iOS源代码
- 0005算法笔记——【分治法】快速排序
- 工业自动化软件
- 表单Post&Get两个长度限制问题的分析
- C++指针的一些小实践
- 用Qt开发游戏时一些问题的解决方法(一)
- Python中的集合:set与frozenset用法举例