Skip to content

Commit 939c7f9

Browse files
committed
Add failing test for #15, as well as tentative feature enum
1 parent d6c0b4c commit 939c7f9

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,24 @@ public enum Feature
6262
* columns that appear after columns for which types are defined. When disabled,
6363
* an exception is thrown for such column values, but if enabled, they are
6464
* silently ignored.
65+
*<p>
66+
* Feature is disabled by default.
6567
*
6668
* @since 2.7
6769
*/
6870
IGNORE_TRAILING_UNMAPPABLE(false),
6971

72+
/**
73+
* Feature that allows skipping input lines that are completely empty, instead
74+
* of being decoded as lines of just a single column with empty String value (or,
75+
* depending on binding, `null`).
76+
*<p>
77+
* Feature is disabled by default.
78+
*
79+
* @since 2.9
80+
*/
81+
SKIP_EMPTY_LINES(false),
82+
7083
/**
7184
* Feature that allows there to be a trailing single extraneous data
7285
* column that is empty. When this feature is disabled, any extraneous
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.fasterxml.jackson.dataformat.csv.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4+
import com.fasterxml.jackson.dataformat.csv.*;
5+
6+
public class SkipEmptyLines15Test extends ModuleTestBase
7+
{
8+
@JsonPropertyOrder({ "age", "name", "cute" })
9+
protected static class Entry {
10+
public int age;
11+
public String name;
12+
public boolean cute;
13+
}
14+
15+
/*
16+
/**********************************************************************
17+
/* Test methods, success
18+
/**********************************************************************
19+
*/
20+
21+
// for [dataformats-text#15]: Allow skipping of empty lines
22+
public void testSkipEmptyLinesFeature() throws Exception
23+
{
24+
final String CSV = "1,\"xyz\"\n\ntrue,\n";
25+
26+
CsvMapper mapper = mapperForCsv();
27+
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
28+
29+
// First, verify default behavior:
30+
31+
String[][] rows = mapper.readValue(CSV, String[][].class);
32+
assertEquals(3, rows.length);
33+
String[] row;
34+
35+
row = rows[0];
36+
assertEquals(2, row.length);
37+
assertEquals("1",row[0]);
38+
assertEquals("xyz", row[1]);
39+
40+
row = rows[1];
41+
assertEquals(1, row.length);
42+
assertEquals("", row[0]);
43+
44+
row = rows[2];
45+
assertEquals(2, row.length);
46+
assertEquals("true", row[0]);
47+
assertEquals("", row[1]);
48+
49+
mapper.enable(CsvParser.Feature.SKIP_EMPTY_LINES);
50+
51+
// when wrapped as an array, we'll get array of Lists:
52+
rows = mapper.readerFor(String[][].class)
53+
.with(CsvParser.Feature.WRAP_AS_ARRAY)
54+
.readValue(CSV);
55+
56+
assertEquals(2, rows.length);
57+
row = rows[0];
58+
assertEquals(2, row.length);
59+
assertEquals("1",row[0]);
60+
assertEquals("xyz", row[1]);
61+
62+
row = rows[1];
63+
assertEquals(2, row.length);
64+
assertEquals("true", row[0]);
65+
assertEquals("", row[1]);
66+
}
67+
}

0 commit comments

Comments
 (0)