Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 852a38c

Browse files
committed
Fix #83
1 parent 71b9583 commit 852a38c

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<groupId>com.fasterxml.jackson.dataformat</groupId>
1010
<artifactId>jackson-dataformat-csv</artifactId>
1111
<name>Jackson-dataformat-CSV</name>
12-
<version>2.6.0-rc5-SNAPSHOT</version>
12+
<version>2.6.0-SNAPSHOT</version>
1313
<packaging>bundle</packaging>
1414
<description>Support for reading and writing CSV-encoded data via Jackson
1515
abstractions.
@@ -23,8 +23,8 @@ abstractions.
2323
</scm>
2424

2525
<properties>
26-
<jackson.version.annotations>2.6.0-rc4</jackson.version.annotations>
27-
<jackson.version.core>2.6.0-rc4</jackson.version.core>
26+
<jackson.version.annotations>2.6.0</jackson.version.annotations>
27+
<jackson.version.core>2.6.0</jackson.version.core>
2828
<!-- Generate PackageVersion.java into this directory. -->
2929
<packageVersion.dir>com/fasterxml/jackson/dataformat/csv</packageVersion.dir>
3030
<packageVersion.package>${project.groupId}.csv</packageVersion.package>

release-notes/CREDITS

+3
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ David Navas (davidnavas@github)
4141
* Contributed #75: Support escapes at beginning of the file
4242
(2.5.3)
4343

44+
sothmann@github)
4445

46+
* Reported #83: Serializing List with null values leads to corrupt CSV
47+
(2.6.0)

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project: jackson-dataformat-csv
99
#72: Recognize the configured "null value" (String) also in reader-infrastructure.
1010
(requested by flappingeagle@github)
1111
#74: Problems with ordering, `@JsonPropertyOrder` losing alphabetic ordering
12+
#83: Serializing List with null values leads to corrupt CSV
13+
(reported by sothmann@github)
1214
- Removed type `CsvObjectReader`, sub-classing not needed at this point,
1315
just complicates handling (for now)
1416

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,13 @@ public void writeBoolean(boolean state) throws IOException
641641
public void writeNull() throws IOException
642642
{
643643
_verifyValueWrite("write null value");
644+
644645
if (!_skipValue) {
645646
if (_arraySeparator >= 0) {
646647
_addToArray(_schema.getNullValueOrEmpty());
647-
} else if (_writeContext.inRoot()) { // as per [#69]
648+
} else if (!_writeContext.inObject()) { // as per [#69]
649+
// note: 'root' not enough, for case of wrap-as array, or serialize List
650+
648651
// or, to write 'empty Object' (for common case), would
649652
// write single null, then finish row, like so:
650653
/*

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

+41
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,53 @@
11
package com.fasterxml.jackson.dataformat.csv.deser;
22

3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
36
import com.fasterxml.jackson.databind.*;
47
import com.fasterxml.jackson.dataformat.csv.*;
58

69
public class NullReadTest extends ModuleTestBase
710
{
811
final CsvMapper MAPPER = mapperForCsv();
912

13+
@JsonPropertyOrder({ "prop1", "prop2", "prop3" })
14+
static class Pojo83 {
15+
public String prop1;
16+
public String prop2;
17+
public int prop3;
18+
19+
protected Pojo83() { }
20+
public Pojo83(String a, String b, int c) {
21+
prop1 = a;
22+
prop2 = b;
23+
prop3 = c;
24+
}
25+
}
26+
27+
/*
28+
/**********************************************************************
29+
/* Test methods
30+
/**********************************************************************
31+
*/
32+
33+
public void testNullIssue83() throws Exception
34+
{
35+
CsvMapper mapper = new CsvMapper();
36+
CsvSchema schema = mapper.schemaFor(Pojo83.class);
37+
final ObjectWriter writer = mapper.writer(schema);
38+
39+
List<Pojo83> list = Arrays.asList(
40+
new Pojo83("foo", "bar", 123),
41+
null,
42+
new Pojo83("test", "abc", 42));
43+
44+
String expectedCsv = "foo,bar,123\ntest,abc,42\n";
45+
String actualCsv = writer.writeValueAsString(list);
46+
47+
System.err.println("CSV:["+actualCsv+"]");
48+
assertEquals(expectedCsv, actualCsv);
49+
}
50+
1051
// For [dataformat-csv#72]: recognize "null value" for reading too
1152
public void testReadNullValue72() throws Exception
1253
{

0 commit comments

Comments
 (0)