We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
在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;