1
1
package tools .jackson .databind .cfg ;
2
2
3
- import tools .jackson .databind .DeserializationFeature ;
3
+ import tools .jackson .databind .DatabindException ;
4
4
5
5
/**
6
6
* New Datatype-specific configuration options related to handling of
7
7
* {@link java.lang.Enum} types.
8
8
*/
9
9
public enum EnumFeature implements DatatypeFeature
10
10
{
11
+ /*
12
+ /**********************************************************************
13
+ /* READ
14
+ /**********************************************************************
15
+ */
16
+
11
17
/**
12
18
* Feature that determines standard deserialization mechanism used for
13
19
* Enum values: if enabled, Enums are assumed to have been serialized using
@@ -22,6 +28,81 @@ public enum EnumFeature implements DatatypeFeature
22
28
*/
23
29
READ_ENUM_KEYS_USING_INDEX (false ),
24
30
31
+ /**
32
+ * Feature that determines whether JSON integer numbers are valid
33
+ * values to be used for deserializing Java enum values.
34
+ * If set to 'false' numbers are acceptable and are used to map to
35
+ * ordinal() of matching enumeration value; if 'true', numbers are
36
+ * not allowed and a {@link DatabindException} will be thrown.
37
+ * Latter behavior makes sense if there is concern that accidental
38
+ * mapping from integer values to enums might happen (and when enums
39
+ * are always serialized as JSON Strings)
40
+ *<p>
41
+ * Feature used to be one of {@link tools.jackson.databind.DeserializationFeature}s
42
+ * in Jackson 2.x but was moved here in 3.0.
43
+ *<p>
44
+ * Feature is disabled by default.
45
+ */
46
+ FAIL_ON_NUMBERS_FOR_ENUMS (false ),
47
+
48
+ /**
49
+ * Feature that determines the deserialization mechanism used for
50
+ * Enum values: if enabled, Enums are assumed to have been serialized using
51
+ * return value of {@code Enum.toString()};
52
+ * if disabled, return value of {@code Enum.name()} is assumed to have been used.
53
+ *<p>
54
+ * Note: this feature should usually have same value
55
+ * as {@link #WRITE_ENUMS_USING_TO_STRING}.
56
+ *<p>
57
+ * Feature used to be one of {@link tools.jackson.databind.DeserializationFeature}s
58
+ * in Jackson 2.x but was moved here in 3.0.
59
+ *<p>
60
+ * Feature is enabled by default as of Jackson 3.0 (in 2.x it was disabled).
61
+ */
62
+ READ_ENUMS_USING_TO_STRING (true ),
63
+
64
+ /**
65
+ * Feature that allows unknown Enum values to be parsed as {@code null} values.
66
+ * If disabled, unknown Enum values will throw exceptions.
67
+ * <p>
68
+ * Note that in some cases this will effectively ignore unknown {@code Enum} values,
69
+ * e.g. when the unknown values are used as keys of {@link java.util.EnumMap}
70
+ * or values of {@link java.util.EnumSet}: this is because these data structures cannot
71
+ * store {@code null} values.
72
+ * <p>
73
+ * Also note that this feature has lower precedence than
74
+ * {@link #READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE},
75
+ * meaning this feature will work only if latter feature is disabled.
76
+ *<p>
77
+ * Feature used to be one of {@link tools.jackson.databind.DeserializationFeature}s
78
+ * in Jackson 2.x but was moved here in 3.0.
79
+ *<p>
80
+ * Feature is disabled by default.
81
+ */
82
+ READ_UNKNOWN_ENUM_VALUES_AS_NULL (false ),
83
+
84
+ /**
85
+ * Feature that allows unknown Enum values to be ignored and replaced by a predefined value specified through
86
+ * {@link com.fasterxml.jackson.annotation.JsonEnumDefaultValue @JsonEnumDefaultValue} annotation.
87
+ * If disabled, unknown Enum values will throw exceptions.
88
+ * If enabled, but no predefined default Enum value is specified, an exception will be thrown as well.
89
+ * <p>
90
+ * Note that this feature has higher precedence than {@link #READ_UNKNOWN_ENUM_VALUES_AS_NULL}.
91
+ *<p>
92
+ * Feature used to be one of {@link tools.jackson.databind.DeserializationFeature}s
93
+ * in Jackson 2.x but was moved here in 3.0.
94
+ *<p>
95
+ * Feature is disabled by default.
96
+ */
97
+ READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE (false ),
98
+
99
+ /*
100
+ /**********************************************************************
101
+ /* WRITE
102
+ /**********************************************************************
103
+ */
104
+
105
+
25
106
/**
26
107
* Feature that determines standard serialization mechanism used for
27
108
* Enum values: if enabled, return value of <code>Enum.name().toLowerCase()</code>
@@ -43,7 +124,7 @@ public enum EnumFeature implements DatatypeFeature
43
124
* is used; if disabled, return value of <code>Enum.name()</code> is used.
44
125
*<p>
45
126
* Note: this feature should usually have same value
46
- * as {@link DeserializationFeature #READ_ENUMS_USING_TO_STRING}.
127
+ * as {@link #READ_ENUMS_USING_TO_STRING}.
47
128
*<p>
48
129
* Feature used to be one of {@link tools.jackson.databind.SerializationFeature}s
49
130
* in Jackson 2.x but was moved here in 3.0.
0 commit comments