View Javadoc
1   package edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.core.json;
2   
3   import edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.core.*;
4   
5   /**
6    * Token reader (parser) features specific to JSON backend.
7    * Eventual replacement for JSON-specific {@link edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.core.JsonParser.Feature}s.
8    *
9    * @since 2.10
10   */
11  public enum JsonReadFeature
12      implements FormatFeature
13  {
14      // // // Support for non-standard data format constructs: comments
15  
16      /**
17       * Feature that determines whether parser will allow use
18       * of Java/C/C++ style comments (both '/'+'*' and
19       * '//' varieties) within parsed content or not.
20       *<p>
21       * Since JSON specification does not mention comments as legal
22       * construct,
23       * this is a non-standard feature; however, in the wild
24       * this is extensively used. As such, feature is
25       * <b>disabled by default</b> for parsers and must be
26       * explicitly enabled.
27       */
28      ALLOW_JAVA_COMMENTS(false, JsonParser.Feature.ALLOW_COMMENTS),
29  
30      /**
31       * Feature that determines whether parser will allow use
32       * of YAML comments, ones starting with '#' and continuing
33       * until the end of the line. This commenting style is common
34       * with scripting languages as well.
35       *<p>
36       * Since JSON specification does not mention comments as legal
37       * construct,
38       * this is a non-standard feature. As such, feature is
39       * <b>disabled by default</b> for parsers and must be
40       * explicitly enabled.
41       */
42      ALLOW_YAML_COMMENTS(false, JsonParser.Feature.ALLOW_YAML_COMMENTS),
43  
44      // // // Support for non-standard data format constructs: quoting/escaping
45  
46      /**
47       * Feature that determines whether parser will allow use
48       * of single quotes (apostrophe, character '\'') for
49       * quoting Strings (names and String values). If so,
50       * this is in addition to other acceptable markers.
51       *<p>
52       * Since JSON specification requires use of double quotes for
53       * field names,
54       * this is a non-standard feature, and as such disabled by default.
55       */
56      ALLOW_SINGLE_QUOTES(false, JsonParser.Feature.ALLOW_SINGLE_QUOTES),
57  
58      /**
59       * Feature that determines whether parser will allow use
60       * of unquoted field names (which is allowed by Javascript,
61       * but not by JSON specification).
62       *<p>
63       * Since JSON specification requires use of double quotes for
64       * field names,
65       * this is a non-standard feature, and as such disabled by default.
66       */
67      ALLOW_UNQUOTED_FIELD_NAMES(false, JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES),
68  
69      /**
70       * Feature that determines whether parser will allow
71       * JSON Strings to contain unescaped control characters
72       * (ASCII characters with value less than 32, including
73       * tab and line feed characters) or not.
74       * If feature is set false, an exception is thrown if such a
75       * character is encountered.
76       *<p>
77       * Since JSON specification requires quoting for all control characters,
78       * this is a non-standard feature, and as such disabled by default.
79       */
80      @SuppressWarnings("deprecation")
81      ALLOW_UNESCAPED_CONTROL_CHARS(false, JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS),
82  
83      /**
84       * Feature that can be enabled to accept quoting of all character
85       * using backslash quoting mechanism: if not enabled, only characters
86       * that are explicitly listed by JSON specification can be thus
87       * escaped (see JSON spec for small list of these characters)
88       *<p>
89       * Since JSON specification requires quoting for all control characters,
90       * this is a non-standard feature, and as such disabled by default.
91       */
92      @SuppressWarnings("deprecation")
93      ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER(false, JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER),
94  
95      // // // Support for non-standard data format constructs: number representations
96      
97      /**
98       * Feature that determines whether parser will allow
99       * JSON integral numbers to start with additional (ignorable) 
100      * zeroes (like: 000001). If enabled, no exception is thrown, and extra
101      * nulls are silently ignored (and not included in textual representation
102      * exposed via {@link JsonParser#getText}).
103      *<p>
104      * Since JSON specification does not allow leading zeroes,
105      * this is a non-standard feature, and as such disabled by default.
106      */
107     @SuppressWarnings("deprecation")
108     ALLOW_LEADING_ZEROS_FOR_NUMBERS(false, JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS),
109 
110     /**
111      * Feature that determines whether parser will allow
112      * JSON decimal numbers to start with a decimal point
113      * (like: .123). If enabled, no exception is thrown, and the number
114      * is parsed as though a leading 0 had been present.
115      *<p>
116      * Since JSON specification does not allow leading decimal,
117      * this is a non-standard feature, and as such disabled by default.
118      *
119      * @since 2.11
120      */
121     @SuppressWarnings("deprecation")
122     ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS(false, JsonParser.Feature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS),
123 
124     /**
125      * Feature that allows parser to recognize set of
126      * "Not-a-Number" (NaN) tokens as legal floating number
127      * values (similar to how many other data formats and
128      * programming language source code allows it).
129      * Specific subset contains values that
130      * <a href="http://www.w3.org/TR/xmlschema-2/">XML Schema</a>
131      * (see section 3.2.4.1, Lexical Representation)
132      * allows (tokens are quoted contents, not including quotes):
133      *<ul>
134      *  <li>"INF" (for positive infinity), as well as alias of "Infinity"
135      *  <li>"-INF" (for negative infinity), alias "-Infinity"
136      *  <li>"NaN" (for other not-a-numbers, like result of division by zero)
137      *</ul>
138      *<p>
139      * Since JSON specification does not allow use of such values,
140      * this is a non-standard feature, and as such disabled by default.
141      */
142     @SuppressWarnings("deprecation")
143     ALLOW_NON_NUMERIC_NUMBERS(false, JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS),
144 
145     // // // Support for non-standard data format constructs: array/value separators
146      
147     /**
148      * Feature allows the support for "missing" values in a JSON array: missing
149      * value meaning sequence of two commas, without value in-between but only
150      * optional white space.
151      * Enabling this feature will expose "missing" values as {@link JsonToken#VALUE_NULL}
152      * tokens, which typically become Java nulls in arrays and {@link java.util.Collection}
153      * in data-binding.
154      * <p>
155      * For example, enabling this feature will represent a JSON array <code>["value1",,"value3",]</code>
156      * as <code>["value1", null, "value3", null]</code> 
157      * <p>
158      * Since the JSON specification does not allow missing values this is a non-compliant JSON
159      * feature and is disabled by default.
160      */
161     @SuppressWarnings("deprecation")
162     ALLOW_MISSING_VALUES(false, JsonParser.Feature.ALLOW_MISSING_VALUES),
163 
164     /**
165      * Feature that determines whether {@link JsonParser} will allow for a single trailing
166      * comma following the final value (in an Array) or member (in an Object). These commas
167      * will simply be ignored.
168      * <p>
169      * For example, when this feature is enabled, <code>[true,true,]</code> is equivalent to
170      * <code>[true, true]</code> and <code>{"a": true,}</code> is equivalent to
171      * <code>{"a": true}</code>.
172      * <p>
173      * When combined with <code>ALLOW_MISSING_VALUES</code>, this feature takes priority, and
174      * the final trailing comma in an array declaration does not imply a missing
175      * (<code>null</code>) value. For example, when both <code>ALLOW_MISSING_VALUES</code>
176      * and <code>ALLOW_TRAILING_COMMA</code> are enabled, <code>[true,true,]</code> is
177      * equivalent to <code>[true, true]</code>, and <code>[true,true,,]</code> is equivalent to
178      * <code>[true, true, null]</code>.
179      * <p>
180      * Since the JSON specification does not permit trailing commas, this is a non-standard
181      * feature, and as such disabled by default.
182      */
183     @SuppressWarnings("deprecation")
184     ALLOW_TRAILING_COMMA(false, JsonParser.Feature.ALLOW_TRAILING_COMMA),
185     ;
186 
187     final private boolean _defaultState;
188     final private int _mask;
189 
190     /**
191      * For backwards compatibility we may need to map to one of existing {@link JsonParser.Feature}s;
192      * if so, this is the feature to enable/disable.
193      */
194     final private JsonParser.Feature _mappedFeature;
195     
196     /**
197      * Method that calculates bit set (flags) of all features that
198      * are enabled by default.
199      *
200      * @return Bit mask of all features that are enabled by default
201      */
202     public static int collectDefaults()
203     {
204         int flags = 0;
205         for (JsonReadFeature f : values()) {
206             if (f.enabledByDefault()) {
207                 flags |= f.getMask();
208             }
209         }
210         return flags;
211     }
212     
213     private JsonReadFeature(boolean defaultState,
214             JsonParser.Feature  mapTo) {
215         _defaultState = defaultState;
216         _mask = (1 << ordinal());
217         _mappedFeature = mapTo;
218     }
219 
220     @Override
221     public boolean enabledByDefault() { return _defaultState; }
222     @Override
223     public int getMask() { return _mask; }
224     @Override
225     public boolean enabledIn(int flags) { return (flags & _mask) != 0; }
226 
227     public JsonParser.Feature mappedFeature() { return _mappedFeature; }
228 }