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

Commit

Permalink
Fix #83
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 17, 2015
1 parent 71b9583 commit 852a38c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
<name>Jackson-dataformat-CSV</name>
<version>2.6.0-rc5-SNAPSHOT</version>
<version>2.6.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<description>Support for reading and writing CSV-encoded data via Jackson
abstractions.
Expand All @@ -23,8 +23,8 @@ abstractions.
</scm>

<properties>
<jackson.version.annotations>2.6.0-rc4</jackson.version.annotations>
<jackson.version.core>2.6.0-rc4</jackson.version.core>
<jackson.version.annotations>2.6.0</jackson.version.annotations>
<jackson.version.core>2.6.0</jackson.version.core>
<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>com/fasterxml/jackson/dataformat/csv</packageVersion.dir>
<packageVersion.package>${project.groupId}.csv</packageVersion.package>
Expand Down
3 changes: 3 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ David Navas (davidnavas@github)
* Contributed #75: Support escapes at beginning of the file
(2.5.3)

sothmann@github)

* Reported #83: Serializing List with null values leads to corrupt CSV
(2.6.0)
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project: jackson-dataformat-csv
#72: Recognize the configured "null value" (String) also in reader-infrastructure.
(requested by flappingeagle@github)
#74: Problems with ordering, `@JsonPropertyOrder` losing alphabetic ordering
#83: Serializing List with null values leads to corrupt CSV
(reported by sothmann@github)
- Removed type `CsvObjectReader`, sub-classing not needed at this point,
just complicates handling (for now)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,13 @@ public void writeBoolean(boolean state) throws IOException
public void writeNull() throws IOException
{
_verifyValueWrite("write null value");

if (!_skipValue) {
if (_arraySeparator >= 0) {
_addToArray(_schema.getNullValueOrEmpty());
} else if (_writeContext.inRoot()) { // as per [#69]
} else if (!_writeContext.inObject()) { // as per [#69]
// note: 'root' not enough, for case of wrap-as array, or serialize List

// or, to write 'empty Object' (for common case), would
// write single null, then finish row, like so:
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
package com.fasterxml.jackson.dataformat.csv.deser;

import java.util.*;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.csv.*;

public class NullReadTest extends ModuleTestBase
{
final CsvMapper MAPPER = mapperForCsv();

@JsonPropertyOrder({ "prop1", "prop2", "prop3" })
static class Pojo83 {
public String prop1;
public String prop2;
public int prop3;

protected Pojo83() { }
public Pojo83(String a, String b, int c) {
prop1 = a;
prop2 = b;
prop3 = c;
}
}

/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/

public void testNullIssue83() throws Exception
{
CsvMapper mapper = new CsvMapper();
CsvSchema schema = mapper.schemaFor(Pojo83.class);
final ObjectWriter writer = mapper.writer(schema);

List<Pojo83> list = Arrays.asList(
new Pojo83("foo", "bar", 123),
null,
new Pojo83("test", "abc", 42));

String expectedCsv = "foo,bar,123\ntest,abc,42\n";
String actualCsv = writer.writeValueAsString(list);

System.err.println("CSV:["+actualCsv+"]");
assertEquals(expectedCsv, actualCsv);
}

// For [dataformat-csv#72]: recognize "null value" for reading too
public void testReadNullValue72() throws Exception
{
Expand Down

0 comments on commit 852a38c

Please sign in to comment.