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

Commit

Permalink
Fixed #66 for 2.5.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 12, 2015
1 parent 4c52901 commit bee4187
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-dataformat-csv
=== Releases ===
------------------------------------------------------------------------

2.5.2 (not yet released)

#66: Deserializing an empty string as an array field return a non-empty list of one empty String
(reported by aksh3ll@github)

2.5.1 (06-Feb-2015)

#65: Buffer recycling not always working
Expand Down
41 changes: 29 additions & 12 deletions src/main/java/com/fasterxml/jackson/dataformat/csv/CsvParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private Feature(boolean defaultState) {
/* State
/**********************************************************************
*/

/**
* Information about parser context, context in which
* the next token is to be parsed (root, array, object).
Expand All @@ -194,18 +194,18 @@ private Feature(boolean defaultState) {
* String value for the current column, if accessed.
*/
protected String _currentValue;

/**
* Index of the column we are exposing
*/
protected int _columnIndex;

/**
* Current logical state of the parser; one of <code>STATE_</code>
* constants.
*/
protected int _state = STATE_DOC_START;

/**
* We will hold on to decoded binary data, for duration of
* current event, so that multiple calls to
Expand All @@ -225,7 +225,7 @@ private Feature(boolean defaultState) {
protected String _arrayValue;

protected char _arraySeparator;

/*
/**********************************************************************
/* Helper objects
Expand All @@ -242,15 +242,15 @@ private Feature(boolean defaultState) {
* of doubled-quotes, escaped characters.
*/
protected final TextBuffer _textBuffer;

protected ByteArrayBuilder _byteArrayBuilder;

/*
/**********************************************************************
/* Life-cycle
/**********************************************************************
*/

public CsvParser(CsvIOContext ctxt, int parserFeatures, int csvFeatures,
ObjectCodec codec, Reader reader)
{
Expand Down Expand Up @@ -282,7 +282,7 @@ public Version version() {
/* Overridden methods
/**********************************************************
*/

@Override
public ObjectCodec getCodec() {
return _objectCodec;
Expand All @@ -292,7 +292,7 @@ public ObjectCodec getCodec() {
public void setCodec(ObjectCodec c) {
_objectCodec = c;
}

@Override
public boolean canUseSchema(FormatSchema schema) {
return (schema instanceof CsvSchema);
Expand Down Expand Up @@ -692,13 +692,30 @@ protected JsonToken _handleArrayValue() throws IOException
return JsonToken.END_ARRAY;
}
int end = _arrayValue.indexOf(_arraySeparator, offset);

if (end < 0) { // last value
_currentValue = (offset == 0) ? _arrayValue : _arrayValue.substring(offset);
_arrayValueStart = end;
_arrayValueStart = end; // end marker, regardless

// 11-Feb-2015, tatu: Tricky, As per [dataformat-csv#66]; empty Strings really
// should not emit any values. Not sure if trim
if (offset == 0) { // no separator
// for now, let's use trimming for checking
if (_arrayValue.isEmpty() || _arrayValue.trim().isEmpty()) {
_parsingContext = _parsingContext.getParent();
_state = STATE_NEXT_ENTRY;
return JsonToken.END_ARRAY;
}
_currentValue = _arrayValue;
} else {
_currentValue = _arrayValue.substring(offset);
}
} else {
_currentValue = _arrayValue.substring(offset, end);
_arrayValueStart = end+1;
}
if (isEnabled(Feature.TRIM_SPACES)) {
_currentValue = _currentValue.trim();
}
return JsonToken.VALUE_STRING;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.fasterxml.jackson.dataformat.csv.deser;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.Arrays;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.csv.*;

// for [dataformat-csv#57]
Expand Down Expand Up @@ -49,6 +50,16 @@ public void testSimpleExplicitStrictTyping() throws Exception
assertEquals(1, v[0]);
assertEquals(2, v[1]);
assertEquals(3, v[2]);

// one more thing: for [dataformat-csv#66]:
value = MAPPER.readerWithTypedSchemaFor(ValueEntry.class)
.readValue("foo,,stuff");
assertNotNull(value);
assertEquals("foo", value.id);
assertEquals("stuff", value.extra);
v = value.values;
assertNotNull(v);
assertEquals(0, v.length);
}

/*
Expand Down

0 comments on commit bee4187

Please sign in to comment.