11package com .fasterxml .jackson .dataformat .csv .deser ;
22
3+ import com .fasterxml .jackson .annotation .JsonPropertyOrder ;
34import com .fasterxml .jackson .databind .ObjectReader ;
5+ import com .fasterxml .jackson .dataformat .csv .CsvMapper ;
46import com .fasterxml .jackson .dataformat .csv .CsvParser ;
57import com .fasterxml .jackson .dataformat .csv .ModuleTestBase ;
68
@@ -15,6 +17,61 @@ public class SkipBlankLines15Test extends ModuleTestBase {
1517 private static final String CSV_WITH_FIRST_BLANK_LINE = "\n 1,\" xyz\" \n true,\n " ;
1618 private static final String CSV_WITH_TRAILING_BLANK_LINES = "1,\" xyz\" \n true,\n \n \n " ;
1719
20+ @ JsonPropertyOrder ({ "age" , "name" , "cute" })
21+ protected static class Entry {
22+ public int age ;
23+ public String name ;
24+ public boolean cute ;
25+ }
26+
27+ // for [dataformats-text#15]: Allow skipping of empty lines
28+ public void testSkipEmptyLinesFeature () throws Exception
29+ {
30+ final String CSV = "1,\" xyz\" \n \n true,\n " ;
31+
32+ CsvMapper mapper = mapperForCsv ();
33+
34+ // First, verify default behavior:
35+
36+ String [][] rows = mapper
37+ .readerFor (String [][].class )
38+ .with (CsvParser .Feature .WRAP_AS_ARRAY )
39+ .readValue (CSV );
40+ assertEquals (3 , rows .length );
41+ String [] row ;
42+
43+ row = rows [0 ];
44+ assertEquals (2 , row .length );
45+ assertEquals ("1" ,row [0 ]);
46+ assertEquals ("xyz" , row [1 ]);
47+
48+ row = rows [1 ];
49+ assertEquals (1 , row .length );
50+ assertEquals ("" , row [0 ]);
51+
52+ row = rows [2 ];
53+ assertEquals (2 , row .length );
54+ assertEquals ("true" , row [0 ]);
55+ assertEquals ("" , row [1 ]);
56+
57+ // when wrapped as an array, we'll get array of Lists:
58+ rows = mapper .readerFor (String [][].class )
59+ .with (CsvParser .Feature .SKIP_EMPTY_LINES )
60+ .with (CsvParser .Feature .WRAP_AS_ARRAY )
61+ .readValue (CSV );
62+
63+ assertEquals (2 , rows .length );
64+ row = rows [0 ];
65+ assertEquals (2 , row .length );
66+ assertEquals ("1" ,row [0 ]);
67+ assertEquals ("xyz" , row [1 ]);
68+
69+ row = rows [1 ];
70+ assertEquals (2 , row .length );
71+ assertEquals ("true" , row [0 ]);
72+ assertEquals ("" , row [1 ]);
73+ }
74+
1875 public void testCsvWithEmptyLineSkipBlankLinesFeatureDisabled () throws Exception {
1976 String [][] rows = mapperForCsvAsArray ().readValue (CSV_WITH_EMPTY_LINE );
2077 // First, verify default behavior:
0 commit comments