This repository has been archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests for #72; fix an accidental exclusion of empty String f…
…or deserialization
- Loading branch information
1 parent
a4c1046
commit b249d53
Showing
4 changed files
with
101 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
src/test/java/com/fasterxml/jackson/dataformat/csv/deser/NullRead72Test.java
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
src/test/java/com/fasterxml/jackson/dataformat/csv/deser/NullReadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.fasterxml.jackson.dataformat.csv.deser; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.dataformat.csv.*; | ||
|
||
public class NullReadTest extends ModuleTestBase | ||
{ | ||
final CsvMapper MAPPER = mapperForCsv(); | ||
|
||
// For [dataformat-csv#72]: recognize "null value" for reading too | ||
public void testReadNullValue72() throws Exception | ||
{ | ||
CsvSchema schema = CsvSchema.builder() | ||
.setNullValue("n/a") | ||
.addColumn("id") | ||
.addColumn("desc") | ||
.build(); | ||
|
||
// start by writing, first | ||
String csv = MAPPER.writer(schema).writeValueAsString(new IdDesc("id", null)); | ||
// MUST use doubling for quotes! | ||
assertEquals("id,n/a\n", csv); | ||
|
||
// but read back | ||
|
||
ObjectReader r = MAPPER.readerFor(IdDesc.class) | ||
.with(schema); | ||
|
||
IdDesc result = r.readValue(csv); | ||
assertNotNull(result); | ||
assertEquals("id", result.id); | ||
assertNull(result.desc); | ||
|
||
// also try the other combination | ||
result = r.readValue("n/a,Whatevs\n"); | ||
assertNotNull(result); | ||
assertNull(result.id); | ||
assertEquals("Whatevs", result.desc); | ||
} | ||
|
||
public void testReadNullValueFromEmptyString() throws Exception | ||
{ | ||
// first: empty String should work as default | ||
CsvSchema schemaWithDefault = CsvSchema.builder() | ||
.addColumn("id") | ||
.addColumn("desc") | ||
.build(); | ||
|
||
// start by writing, first | ||
String csv = MAPPER.writer(schemaWithDefault).writeValueAsString(new IdDesc("id", null)); | ||
assertEquals("id,\n", csv); | ||
|
||
// but read back | ||
|
||
ObjectReader r = MAPPER.readerFor(IdDesc.class).with(schemaWithDefault); | ||
|
||
IdDesc result = r.readValue(csv); | ||
assertNotNull(result); | ||
assertEquals("id", result.id); | ||
assertNull(result.desc); | ||
|
||
// also try the other combination | ||
result = r.readValue(",Whatevs\n"); | ||
assertNotNull(result); | ||
assertNull(result.id); | ||
assertEquals("Whatevs", result.desc); | ||
|
||
// And then with explicit Empty String | ||
CsvSchema schemaWithExplicitEmpty = CsvSchema.builder() | ||
.setNullValue("") | ||
.addColumn("id") | ||
.addColumn("desc") | ||
.build(); | ||
|
||
csv = MAPPER.writer(schemaWithExplicitEmpty).writeValueAsString(new IdDesc("id", null)); | ||
assertEquals("id,\n", csv); | ||
r = MAPPER.readerFor(IdDesc.class).with(schemaWithExplicitEmpty); | ||
result = r.readValue(csv); | ||
assertNotNull(result); | ||
assertEquals("id", result.id); | ||
assertNull(result.desc); | ||
|
||
// and finally with explicit `null` | ||
CsvSchema schemaWithExplicitNull = CsvSchema.builder() | ||
.setNullValue((String) null) | ||
.addColumn("id") | ||
.addColumn("desc") | ||
.build(); | ||
|
||
csv = MAPPER.writer(schemaWithExplicitNull).writeValueAsString(new IdDesc("id", null)); | ||
assertEquals("id,\n", csv); | ||
r = MAPPER.readerFor(IdDesc.class).with(schemaWithExplicitNull); | ||
result = r.readValue(csv); | ||
assertNotNull(result); | ||
assertEquals("id", result.id); | ||
assertNull(result.desc); | ||
} | ||
} |
b249d53
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cowtowncoder Thanks for fixing this so quickly -- there are two tests that are failing, easy fix just change empty strings to null:
Also, any idea of we can expect a 2.6.0 release? And rc4 too -- is there a date associated with it?
b249d53
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dharaburda d'oh. I thought I had run the test suite. Shows me to check in things in a hurry. :)
As to 2.6.0 -- was hoping by end of June, but not happening now. Not 100% sure if there will be rc4 before 2.6.0 final, but regardless next release will happen at earlier on week of july 6th (I'll be on vacation until then). But at the same time, planning to get the release out by mid-July now.