-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
SkipEmptyLines15Test.java
67 lines (53 loc) · 1.94 KB
/
SkipEmptyLines15Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.fasterxml.jackson.dataformat.csv.failing;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.csv.*;
public class SkipEmptyLines15Test extends ModuleTestBase
{
@JsonPropertyOrder({ "age", "name", "cute" })
protected static class Entry {
public int age;
public String name;
public boolean cute;
}
/*
/**********************************************************************
/* Test methods, success
/**********************************************************************
*/
// for [dataformats-text#15]: Allow skipping of empty lines
public void testSkipEmptyLinesFeature() throws Exception
{
final String CSV = "1,\"xyz\"\n\ntrue,\n";
CsvMapper mapper = mapperForCsv();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
// First, verify default behavior:
String[][] rows = mapper.readValue(CSV, String[][].class);
assertEquals(3, rows.length);
String[] row;
row = rows[0];
assertEquals(2, row.length);
assertEquals("1",row[0]);
assertEquals("xyz", row[1]);
row = rows[1];
assertEquals(1, row.length);
assertEquals("", row[0]);
row = rows[2];
assertEquals(2, row.length);
assertEquals("true", row[0]);
assertEquals("", row[1]);
mapper.enable(CsvParser.Feature.SKIP_EMPTY_LINES);
// when wrapped as an array, we'll get array of Lists:
rows = mapper.readerFor(String[][].class)
.with(CsvParser.Feature.WRAP_AS_ARRAY)
.readValue(CSV);
assertEquals(2, rows.length);
row = rows[0];
assertEquals(2, row.length);
assertEquals("1",row[0]);
assertEquals("xyz", row[1]);
row = rows[1];
assertEquals(2, row.length);
assertEquals("true", row[0]);
assertEquals("", row[1]);
}
}