-
Notifications
You must be signed in to change notification settings - Fork 6.5k
WriteEnumUsingOrdinal_cn
高铁 edited this page Mar 17, 2017
·
1 revision
在fastjson中,缺省的序列化设置JSON.DEFAULT_GENERATE_FEATURE配置了SerializerFeature.WriteEnumUsingName,所以输出是默认是name,如果不想使用name,有两种办法。
public static class Model {
public Type type;
}
public static enum Type {
Big, Medium, Small
}
public void test_enum_ordinal() throws Exception {
Model model = new Model();
model.type = Type.Big;
int serializerFeatures = JSON.DEFAULT_GENERATE_FEATURE & ~SerializerFeature.WriteEnumUsingName.mask;
String text = JSON.toJSONString(model, serializerFeatures);
System.out.println(text);
}
JSON.DEFAULT_GENERATE_FEATURE &= ~SerializerFeature.WriteEnumUsingName.mask;
如有需要修改本注脚,请联系阿里巴巴,
© Alibaba Fastjson Develop Team
注明: 版权所有阿里巴巴,请注明版权所有者
If you need to amend this footnote, please contact Alibaba.
© Alibaba Fastjson Develop Team
Note: Copyright Alibaba, please indicate the copyright owner