Skip to content

Commit 46f9347

Browse files
committed
Treat empty values as null in CSVDecoder.
1 parent 0a8dc92 commit 46f9347

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

httprpc-client/src/main/java/org/httprpc/io/CSVDecoder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ public Map<String, String> next() {
7171
LinkedHashMap<String, String> row = new LinkedHashMap<>();
7272

7373
for (int i = 0, n = Math.min(keys.size(), values.size()); i < n; i++) {
74-
row.put(keys.get(i), values.get(i));
74+
String value = values.get(i);
75+
76+
if (!value.isEmpty()) {
77+
row.put(keys.get(i), value);
78+
}
7579
}
7680

7781
hasNext = null;

httprpc-client/src/test/java/org/httprpc/io/CSVDecoderTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
public class CSVDecoderTest {
3131
@Test
3232
public void testRead() throws IOException {
33-
String text = "\"a\",\"b\",\"c\",\"d\"\r\n"
34-
+ "\"A,B,\"\"C\"\" \",1,2.0,true\r\n"
35-
+ "\" D\rÉ\nF\r\n\",2,4.0,false\n";
33+
String text = "\"a\",\"b\",\"c\",\"d\",\"e\"\r\n"
34+
+ "\"A,B,\"\"C\"\" \",1,2.0,true,\r\n"
35+
+ "\" D\rÉ\nF\r\n\",2,4.0,false\r\n"
36+
+ ",3,6.0\n";
3637

3738
List<Map<String, ?>> expected = listOf(
3839
mapOf(
@@ -46,6 +47,10 @@ public void testRead() throws IOException {
4647
entry("b", "2"),
4748
entry("c", "4.0"),
4849
entry("d", "false")
50+
),
51+
mapOf(
52+
entry("b", "3"),
53+
entry("c", "6.0")
4954
)
5055
);
5156

0 commit comments

Comments
 (0)