Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit bee4187

Browse files
committed
Fixed #66 for 2.5.2.
1 parent 4c52901 commit bee4187

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-dataformat-csv
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.5.2 (not yet released)
8+
9+
#66: Deserializing an empty string as an array field return a non-empty list of one empty String
10+
(reported by aksh3ll@github)
11+
712
2.5.1 (06-Feb-2015)
813

914
#65: Buffer recycling not always working

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private Feature(boolean defaultState) {
176176
/* State
177177
/**********************************************************************
178178
*/
179-
179+
180180
/**
181181
* Information about parser context, context in which
182182
* the next token is to be parsed (root, array, object).
@@ -194,18 +194,18 @@ private Feature(boolean defaultState) {
194194
* String value for the current column, if accessed.
195195
*/
196196
protected String _currentValue;
197-
197+
198198
/**
199199
* Index of the column we are exposing
200200
*/
201201
protected int _columnIndex;
202-
202+
203203
/**
204204
* Current logical state of the parser; one of <code>STATE_</code>
205205
* constants.
206206
*/
207207
protected int _state = STATE_DOC_START;
208-
208+
209209
/**
210210
* We will hold on to decoded binary data, for duration of
211211
* current event, so that multiple calls to
@@ -225,7 +225,7 @@ private Feature(boolean defaultState) {
225225
protected String _arrayValue;
226226

227227
protected char _arraySeparator;
228-
228+
229229
/*
230230
/**********************************************************************
231231
/* Helper objects
@@ -242,15 +242,15 @@ private Feature(boolean defaultState) {
242242
* of doubled-quotes, escaped characters.
243243
*/
244244
protected final TextBuffer _textBuffer;
245-
245+
246246
protected ByteArrayBuilder _byteArrayBuilder;
247-
247+
248248
/*
249249
/**********************************************************************
250250
/* Life-cycle
251251
/**********************************************************************
252252
*/
253-
253+
254254
public CsvParser(CsvIOContext ctxt, int parserFeatures, int csvFeatures,
255255
ObjectCodec codec, Reader reader)
256256
{
@@ -282,7 +282,7 @@ public Version version() {
282282
/* Overridden methods
283283
/**********************************************************
284284
*/
285-
285+
286286
@Override
287287
public ObjectCodec getCodec() {
288288
return _objectCodec;
@@ -292,7 +292,7 @@ public ObjectCodec getCodec() {
292292
public void setCodec(ObjectCodec c) {
293293
_objectCodec = c;
294294
}
295-
295+
296296
@Override
297297
public boolean canUseSchema(FormatSchema schema) {
298298
return (schema instanceof CsvSchema);
@@ -692,13 +692,30 @@ protected JsonToken _handleArrayValue() throws IOException
692692
return JsonToken.END_ARRAY;
693693
}
694694
int end = _arrayValue.indexOf(_arraySeparator, offset);
695+
695696
if (end < 0) { // last value
696-
_currentValue = (offset == 0) ? _arrayValue : _arrayValue.substring(offset);
697-
_arrayValueStart = end;
697+
_arrayValueStart = end; // end marker, regardless
698+
699+
// 11-Feb-2015, tatu: Tricky, As per [dataformat-csv#66]; empty Strings really
700+
// should not emit any values. Not sure if trim
701+
if (offset == 0) { // no separator
702+
// for now, let's use trimming for checking
703+
if (_arrayValue.isEmpty() || _arrayValue.trim().isEmpty()) {
704+
_parsingContext = _parsingContext.getParent();
705+
_state = STATE_NEXT_ENTRY;
706+
return JsonToken.END_ARRAY;
707+
}
708+
_currentValue = _arrayValue;
709+
} else {
710+
_currentValue = _arrayValue.substring(offset);
711+
}
698712
} else {
699713
_currentValue = _arrayValue.substring(offset, end);
700714
_arrayValueStart = end+1;
701715
}
716+
if (isEnabled(Feature.TRIM_SPACES)) {
717+
_currentValue = _currentValue.trim();
718+
}
702719
return JsonToken.VALUE_STRING;
703720
}
704721

src/test/java/com/fasterxml/jackson/dataformat/csv/deser/ArrayReadTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.fasterxml.jackson.dataformat.csv.deser;
22

3-
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
3+
import java.util.Arrays;
44

5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
56
import com.fasterxml.jackson.dataformat.csv.*;
67

78
// for [dataformat-csv#57]
@@ -49,6 +50,16 @@ public void testSimpleExplicitStrictTyping() throws Exception
4950
assertEquals(1, v[0]);
5051
assertEquals(2, v[1]);
5152
assertEquals(3, v[2]);
53+
54+
// one more thing: for [dataformat-csv#66]:
55+
value = MAPPER.readerWithTypedSchemaFor(ValueEntry.class)
56+
.readValue("foo,,stuff");
57+
assertNotNull(value);
58+
assertEquals("foo", value.id);
59+
assertEquals("stuff", value.extra);
60+
v = value.values;
61+
assertNotNull(v);
62+
assertEquals(0, v.length);
5263
}
5364

5465
/*

0 commit comments

Comments
 (0)