@@ -30,6 +30,15 @@ public class YAMLParser extends ParserBase
30
30
*/
31
31
public enum Feature implements FormatFeature // in 2.9
32
32
{
33
+ /**
34
+ * Feature that determines whether an empty {@link String} will be parsed
35
+ * as {@code null}. Logic is part of YAML 1.1
36
+ * <a href="https://yaml.org/type/null.html">Null Language-Independent Type</a>.
37
+ *<p>
38
+ * Feature is enabled by default in Jackson 2.12 for backwards-compatibility
39
+ * reasons.
40
+ */
41
+ EMPTY_STRING_AS_NULL (true )
33
42
;
34
43
35
44
final boolean _defaultState ;
@@ -84,6 +93,9 @@ private Feature(boolean defaultState) {
84
93
85
94
protected int _formatFeatures ;
86
95
96
+ // @since 2.12
97
+ protected boolean _cfgEmptyStringsToNull ;
98
+
87
99
/*
88
100
/**********************************************************************
89
101
/* Input sources
@@ -164,9 +176,9 @@ public YAMLParser(IOContext ctxt, BufferRecycler br,
164
176
_formatFeatures = formatFeatures ;
165
177
_reader = reader ;
166
178
_yamlParser = new ParserImpl (new StreamReader (reader ));
179
+ _cfgEmptyStringsToNull = Feature .EMPTY_STRING_AS_NULL .enabledIn (formatFeatures );
167
180
}
168
181
169
-
170
182
@ Override
171
183
public ObjectCodec getCodec () {
172
184
return _objectCodec ;
@@ -260,11 +272,11 @@ protected void _closeInput() throws IOException {
260
272
_reader .close ();
261
273
}
262
274
}
263
-
275
+
264
276
/*
265
- /**********************************************************
277
+ /**********************************************************
266
278
/* FormatFeature support
267
- /**********************************************************
279
+ /**********************************************************
268
280
*/
269
281
270
282
@ Override
@@ -275,6 +287,7 @@ public int getFormatFeatures() {
275
287
@ Override
276
288
public JsonParser overrideFormatFeatures (int values , int mask ) {
277
289
_formatFeatures = (_formatFeatures & ~mask ) | (values & mask );
290
+ _cfgEmptyStringsToNull = Feature .EMPTY_STRING_AS_NULL .enabledIn (_formatFeatures );
278
291
return this ;
279
292
}
280
293
@@ -291,6 +304,7 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
291
304
public JsonParser enable (YAMLParser .Feature f )
292
305
{
293
306
_formatFeatures |= f .getMask ();
307
+ _cfgEmptyStringsToNull = Feature .EMPTY_STRING_AS_NULL .enabledIn (_formatFeatures );
294
308
return this ;
295
309
}
296
310
@@ -301,6 +315,7 @@ public JsonParser enable(YAMLParser.Feature f)
301
315
public JsonParser disable (YAMLParser .Feature f )
302
316
{
303
317
_formatFeatures &= ~f .getMask ();
318
+ _cfgEmptyStringsToNull = Feature .EMPTY_STRING_AS_NULL .enabledIn (_formatFeatures );
304
319
return this ;
305
320
}
306
321
@@ -520,13 +535,11 @@ protected JsonToken _decodeScalar(ScalarEvent scalar) throws IOException
520
535
_textValue = value ;
521
536
_cleanedTextValue = null ;
522
537
523
- // [dataformats-text#130]: uncomment for 2.13 either as-is, or
524
- // behind a new feature
525
- /*
526
- if (value.isEmpty()) {
538
+ // [dataformats-text#130]: Allow determining whether empty String is
539
+ // coerced into null or not
540
+ if (!_cfgEmptyStringsToNull && value .isEmpty ()) {
527
541
return JsonToken .VALUE_STRING ;
528
542
}
529
- */
530
543
531
544
// we may get an explicit tag, if so, use for corroborating...
532
545
String typeTag = scalar .getTag ();
0 commit comments