@@ -298,6 +298,11 @@ private Feature(boolean defaultState) {
298
298
*/
299
299
protected int _columnCount = 0 ;
300
300
301
+ /**
302
+ * @since 2.12
303
+ */
304
+ protected boolean _cfgEmptyStringAsNull ;
305
+
301
306
/*
302
307
/**********************************************************************
303
308
/* State
@@ -395,6 +400,7 @@ public CsvParser(CsvIOContext ctxt, int stdFeatures, int csvFeatures,
395
400
_parsingContext = JsonReadContext .createRootContext (dups );
396
401
_reader = new CsvDecoder (this , ctxt , reader , _schema , _textBuffer ,
397
402
stdFeatures , csvFeatures );
403
+ _cfgEmptyStringAsNull = CsvParser .Feature .EMPTY_STRING_AS_NULL .enabledIn (csvFeatures );
398
404
}
399
405
400
406
/*
@@ -495,6 +501,7 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
495
501
if (oldF != newF ) {
496
502
_formatFeatures = newF ;
497
503
_reader .overrideFormatFeatures (newF );
504
+ _cfgEmptyStringAsNull = CsvParser .Feature .EMPTY_STRING_AS_NULL .enabledIn (_formatFeatures );
498
505
}
499
506
return this ;
500
507
}
@@ -512,6 +519,7 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
512
519
public JsonParser enable (Feature f )
513
520
{
514
521
_formatFeatures |= f .getMask ();
522
+ _cfgEmptyStringAsNull = CsvParser .Feature .EMPTY_STRING_AS_NULL .enabledIn (_formatFeatures );
515
523
return this ;
516
524
}
517
525
@@ -522,6 +530,7 @@ public JsonParser enable(Feature f)
522
530
public JsonParser disable (Feature f )
523
531
{
524
532
_formatFeatures &= ~f .getMask ();
533
+ _cfgEmptyStringAsNull = CsvParser .Feature .EMPTY_STRING_AS_NULL .enabledIn (_formatFeatures );
525
534
return this ;
526
535
}
527
536
@@ -944,6 +953,9 @@ protected JsonToken _handleNamedValue() throws IOException
944
953
return JsonToken .VALUE_NULL ;
945
954
}
946
955
}
956
+ if (_cfgEmptyStringAsNull && "" .equals (_currentValue )) {
957
+ return JsonToken .VALUE_NULL ;
958
+ }
947
959
return JsonToken .VALUE_STRING ;
948
960
}
949
961
@@ -968,6 +980,9 @@ protected JsonToken _handleUnnamedValue() throws IOException
968
980
return JsonToken .VALUE_NULL ;
969
981
}
970
982
}
983
+ if (_cfgEmptyStringAsNull && "" .equals (_currentValue )) {
984
+ return JsonToken .VALUE_NULL ;
985
+ }
971
986
return JsonToken .VALUE_STRING ;
972
987
}
973
988
@@ -1010,6 +1025,9 @@ protected JsonToken _handleArrayValue() throws IOException
1010
1025
return JsonToken .VALUE_NULL ;
1011
1026
}
1012
1027
}
1028
+ if (_cfgEmptyStringAsNull && "" .equals (_currentValue )) {
1029
+ return JsonToken .VALUE_NULL ;
1030
+ }
1013
1031
return JsonToken .VALUE_STRING ;
1014
1032
}
1015
1033
@@ -1055,7 +1073,6 @@ protected JsonToken _handleExtraColumn(String value) throws IOException
1055
1073
if (next == null ) { // should end of record or input
1056
1074
return _handleObjectRowEnd ();
1057
1075
}
1058
- System .err .println ("... yet we did NOT skip" );
1059
1076
}
1060
1077
}
1061
1078
// 21-May-2015, tatu: Need to enter recovery mode, to skip remainder of the line
@@ -1167,9 +1184,8 @@ public String getText() throws IOException {
1167
1184
if (_currToken == JsonToken .FIELD_NAME ) {
1168
1185
return _currentName ;
1169
1186
}
1170
- if (_currentValue .equals ("" )) {
1171
- return isEnabled (CsvParser .Feature .EMPTY_STRING_AS_NULL ) ? null : _currentValue ;
1172
- }
1187
+ // 08-Sep-2020, tatu: Used to check for empty String wrt EMPTY_STRING_AS_NULL
1188
+ // here, but now demoted to actual "nextToken()" handling
1173
1189
return _currentValue ;
1174
1190
}
1175
1191
0 commit comments