Skip to content

Commit 9039e78

Browse files
authored
Merge part of #471 ahead of it (to reduce diff) (#472)
1 parent b41a64e commit 9039e78

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvParser.java

+22-18
Original file line numberDiff line numberDiff line change
@@ -1021,12 +1021,7 @@ protected JsonToken _handleNamedValue() throws IOException
10211021
}
10221022
}
10231023
_state = STATE_NEXT_ENTRY;
1024-
if (_nullValue != null) {
1025-
if (_nullValue.equals(_currentValue)) {
1026-
return JsonToken.VALUE_NULL;
1027-
}
1028-
}
1029-
if (_cfgEmptyStringAsNull && "".equals(_currentValue)) {
1024+
if (_isNullValue(_currentValue)) {
10301025
return JsonToken.VALUE_NULL;
10311026
}
10321027
return JsonToken.VALUE_STRING;
@@ -1048,12 +1043,7 @@ protected JsonToken _handleUnnamedValue() throws IOException
10481043
// state remains the same
10491044
_currentValue = next;
10501045
++_columnIndex;
1051-
if (_nullValue != null) {
1052-
if (_nullValue.equals(next)) {
1053-
return JsonToken.VALUE_NULL;
1054-
}
1055-
}
1056-
if (_cfgEmptyStringAsNull && "".equals(_currentValue)) {
1046+
if (_isNullValue(next)) {
10571047
return JsonToken.VALUE_NULL;
10581048
}
10591049
return JsonToken.VALUE_STRING;
@@ -1093,12 +1083,7 @@ protected JsonToken _handleArrayValue() throws IOException
10931083
if (isEnabled(Feature.TRIM_SPACES)) {
10941084
_currentValue = _currentValue.trim();
10951085
}
1096-
if (_nullValue != null) {
1097-
if (_nullValue.equals(_currentValue)) {
1098-
return JsonToken.VALUE_NULL;
1099-
}
1100-
}
1101-
if (_cfgEmptyStringAsNull && "".equals(_currentValue)) {
1086+
if (_isNullValue(_currentValue)) {
11021087
return JsonToken.VALUE_NULL;
11031088
}
11041089
return JsonToken.VALUE_STRING;
@@ -1448,4 +1433,23 @@ protected void _startArray(CsvSchema.Column column)
14481433
}
14491434
_arraySeparator = sep;
14501435
}
1436+
1437+
1438+
/**
1439+
* Helper method called to check whether specified String value should be considered
1440+
* "null" value, if so configured.
1441+
*
1442+
* @since 2.17.1
1443+
*/
1444+
protected boolean _isNullValue(String value) {
1445+
if (_nullValue != null) {
1446+
if (_nullValue.equals(value)) {
1447+
return true;
1448+
}
1449+
}
1450+
if (_cfgEmptyStringAsNull && _currentValue.isEmpty()) {
1451+
return true;
1452+
}
1453+
return false;
1454+
}
14511455
}

0 commit comments

Comments
 (0)