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

Commit 327fa1c

Browse files
committed
Fix #41
1 parent 5190aaf commit 327fa1c

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

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

+16-7
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ public void setSchema(FormatSchema schema)
293293
}
294294

295295
@Override
296-
public int releaseBuffered(Writer out) throws IOException
297-
{
296+
public int releaseBuffered(Writer out) throws IOException {
298297
return _reader.releaseBuffered(out);
299298
}
300299

@@ -397,14 +396,12 @@ public Object getInputSource() {
397396
*/
398397

399398
@Override
400-
public String getCurrentName() throws IOException, JsonParseException
401-
{
399+
public String getCurrentName() throws IOException, JsonParseException {
402400
return _currentName;
403401
}
404402

405403
@Override
406-
public void overrideCurrentName(String name)
407-
{
404+
public void overrideCurrentName(String name) {
408405
_currentName = name;
409406
}
410407

@@ -613,21 +610,33 @@ protected void _readHeaderLine() throws IOException, JsonParseException
613610
// For now we do not store char[] representation...
614611
@Override
615612
public boolean hasTextCharacters() {
613+
if (_currToken == JsonToken.FIELD_NAME) {
614+
return false;
615+
}
616616
return _textBuffer.hasTextAsCharacters();
617617
}
618-
618+
619619
@Override
620620
public String getText() throws IOException, JsonParseException {
621+
if (_currToken == JsonToken.FIELD_NAME) {
622+
return _currentName;
623+
}
621624
return _currentValue;
622625
}
623626

624627
@Override
625628
public char[] getTextCharacters() throws IOException, JsonParseException {
629+
if (_currToken == JsonToken.FIELD_NAME) {
630+
return _currentName.toCharArray();
631+
}
626632
return _textBuffer.contentsAsArray();
627633
}
628634

629635
@Override
630636
public int getTextLength() throws IOException, JsonParseException {
637+
if (_currToken == JsonToken.FIELD_NAME) {
638+
return _currentName.length();
639+
}
631640
return _textBuffer.size();
632641
}
633642

src/test/java/com/fasterxml/jackson/dataformat/csv/TestParser.java

+21
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,25 @@ public void testStringNullHandlingForInteger() throws Exception
150150
assertNull(result.y);
151151
assertNull(result.z);
152152
}
153+
154+
// [Issue#41]
155+
public void testIncorrectDups41() throws Exception
156+
{
157+
final String INPUT = "\"foo\",\"bar\",\"foo\"";
158+
CsvSchema schema = CsvSchema.builder().addColumn("Col1").addColumn("Col2")
159+
.addColumn("Col3").build();
160+
161+
MappingIterator<Object> iter = new CsvMapper().reader(Object.class)
162+
.with(schema).readValues(INPUT);
163+
164+
Map<?,?> m = (Map<?,?>) iter.next();
165+
assertFalse(iter.hasNextValue());
166+
167+
if (m.size() != 3) {
168+
fail("Should have 3 entries, but got: "+m);
169+
}
170+
assertEquals("foo", m.get("Col1"));
171+
assertEquals("bar", m.get("Col2"));
172+
assertEquals("foo", m.get("Col3"));
173+
}
153174
}

0 commit comments

Comments
 (0)