Skip to content

Commit ae49636

Browse files
committed
Merge branch '2.11'
2 parents c388d4a + 997858d commit ae49636

File tree

3 files changed

+95
-5
lines changed

3 files changed

+95
-5
lines changed

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/SkipEmptyLines191Test.java

+87-3
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,106 @@
22

33
import java.io.Reader;
44
import java.io.StringReader;
5+
import java.io.StringWriter;
56
import java.util.List;
67
import java.util.Map;
8+
import java.util.Random;
9+
10+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
11+
12+
import com.fasterxml.jackson.databind.MappingIterator;
13+
import com.fasterxml.jackson.databind.ObjectReader;
714

815
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
16+
import com.fasterxml.jackson.dataformat.csv.CsvParser;
917
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
1018
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
1119

1220
// [dataformats-text#191]
21+
// [dataformats-text#174]
1322
public class SkipEmptyLines191Test extends ModuleTestBase {
1423

15-
private static String COL_1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
16-
private static String COL_2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
24+
// [dataformats-text#174]
25+
@JsonPropertyOrder({ "timestamp", "random" })
26+
static class Row174 {
27+
private int timestamp;
28+
private String random;
29+
30+
public int getTimestamp() {
31+
return timestamp;
32+
}
33+
34+
public void setTimestamp(int timestamp) {
35+
this.timestamp = timestamp;
36+
}
37+
38+
public String getRandom() {
39+
return random;
40+
}
41+
42+
public void setRandom(String random) {
43+
this.random = random;
44+
}
45+
46+
@Override
47+
public String toString() {
48+
return "Row{timestamp=" + timestamp + ", random='" + random + "'}";
49+
}
50+
}
51+
52+
/*
53+
/**********************************************************************
54+
/* Test methods
55+
/**********************************************************************
56+
*/
57+
58+
private final static CsvMapper MAPPER = new CsvMapper();
59+
60+
// [dataformats-text#174]
61+
public void testEmptyLines174() throws Exception
62+
{
63+
final StringWriter sw = new StringWriter(50000);
64+
int lineCount = 0;
65+
final Random rnd = new Random();
66+
67+
while (lineCount < 4000) {
68+
sw.append("\"" + System.currentTimeMillis()/1000 + "\",\"" + randomString(rnd) + "\"\n");
69+
++lineCount;
70+
}
71+
final String doc = sw.toString();
72+
73+
ObjectReader objectReader = MAPPER
74+
.enable(CsvParser.Feature.SKIP_EMPTY_LINES)
75+
.readerFor(Row174.class)
76+
.with(MAPPER.schemaFor(Row174.class));
77+
78+
MappingIterator<Row174> iterator = objectReader.readValues(doc);
79+
Row174 data = null;
80+
lineCount = 0;
81+
while (iterator.hasNext()) {
82+
++lineCount;
83+
try {
84+
data = iterator.next();
85+
} catch (Exception e) {
86+
fail("Failed on row #"+lineCount+", previous row: "+data);
87+
}
88+
}
89+
iterator.close();
90+
}
91+
92+
private String randomString(Random rnd) {
93+
StringBuilder sb = new StringBuilder();
94+
for (int i = 0; i < 10; ++i) {
95+
sb.append((char) ('A' + (rnd.nextInt() & 0xF)));
96+
}
97+
return sb.toString();
98+
}
1799

18100
// [dataformats-text#191]: IndexArrayOutOfBounds at 4000
19101
public void testBigCsvFile() throws Exception
20102
{
103+
final String COL_1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
104+
final String COL_2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
21105
CsvSchema schema = CsvSchema
22106
.emptySchema()
23107
.withHeader()
@@ -26,7 +110,7 @@ public void testBigCsvFile() throws Exception
26110
.withComments();
27111

28112
try (Reader r = new StringReader(_generate4kDoc())) {
29-
List<Map<String, String>> result = new CsvMapper()
113+
List<Map<String, String>> result = MAPPER
30114
.readerFor(Map.class)
31115
.with(schema)
32116
.<Map<String, String>>readValues(r)

release-notes/CREDITS-2.x

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Fabrice Delhoste (spifd@github)
2323

2424
Thomas Hauk (thauk-copperleaf@github)
2525

26-
* Contibuted #84 (yaml): Add option to allow use of platform-linefeed
26+
* Contributed #84 (yaml): Add option to allow use of platform-linefeed
2727
(`YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS`)
2828
(2.9.6)
2929

@@ -103,7 +103,6 @@ Jochen Schalanda (joschi@github)
103103
* Reported #187: Update to SnakeYAML to 1.26 (from 1.24) to address CVE-2017-18640
104104
(2.10.4)
105105

106-
107106
Tyler Carpenter-Rivers (tyler2cr@github)
108107
#7: Add `CsvParser.Feature.EMPTY_STRING_AS_NULL` to allow coercing empty Strings
109108
into `null` values
@@ -112,3 +111,8 @@ Tyler Carpenter-Rivers (tyler2cr@github)
112111
* Reported, constributed fix for #180: (yaml) YAMLGenerator serializes string with special
113112
chars unquoted when using `MINIMIZE_QUOTES` mode
114113
(2.11.0)
114+
115+
Yohann BONILLO (ybonillo@github)
116+
117+
* Reported #174: (csv) `CsvParser.Feature.SKIP_EMPTY_LINES` results in a mapping error
118+
(2.11.0)

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Modules:
1515
(contributed by Tyler C-R)
1616
#115: (csv) JsonProperty index is not honored by CsvSchema builder
1717
-- actually fixed by [databind#2555]
18+
#174: (csv) `CsvParser.Feature.SKIP_EMPTY_LINES` results in a mapping error
19+
(reported by Yohann B)
1820
#180: (yaml) YAMLGenerator serializes string with special chars unquoted when
1921
using `MINIMIZE_QUOTES` mode
2022
(reported, fix contributed by Timo R)

0 commit comments

Comments
 (0)