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.
- Loading branch information
1 parent
1833512
commit 2bcdcb5
Showing
3 changed files
with
115 additions
and
18 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
76 changes: 76 additions & 0 deletions
76
src/test/java/com/fasterxml/jackson/dataformat/csv/deser/IgnoreUnmappableTest.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,76 @@ | ||
package com.fasterxml.jackson.dataformat.csv.deser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.MappingIterator; | ||
|
||
import com.fasterxml.jackson.dataformat.csv.*; | ||
|
||
/** | ||
* Test(s) for [dataformat-csv#95] | ||
*/ | ||
public class IgnoreUnmappableTest extends ModuleTestBase | ||
{ | ||
final CsvMapper MAPPER = mapperForCsv(); | ||
|
||
@JsonPropertyOrder({ "first", "second" }) | ||
static class StringPair { | ||
public String first, second; | ||
} | ||
|
||
public void testSimpleIgnoral() throws Exception | ||
{ | ||
final String INPUT = "a,b,c,foo\nd,e\nf,g,h,i\n"; | ||
final CsvSchema schema = MAPPER.schemaFor(StringPair.class); | ||
|
||
// first: throw exception(s) with default settings | ||
MappingIterator<StringPair> it = MAPPER.readerFor(StringPair.class) | ||
.with(schema) | ||
.without(CsvParser.Feature.IGNORE_TRAILING_UNMAPPABLE) | ||
.readValues(INPUT); | ||
|
||
try { | ||
it.nextValue(); | ||
fail("Should not have passed"); | ||
} catch (JsonMappingException e) { | ||
verifyException(e, "Too many entries"); | ||
} | ||
|
||
// yet second one ought to work | ||
StringPair pair = it.nextValue(); | ||
assertEquals("d", pair.first); | ||
assertEquals("e", pair.second); | ||
|
||
// and not third, again | ||
try { | ||
it.nextValue(); | ||
fail("Should not have passed"); | ||
} catch (JsonMappingException e) { | ||
verifyException(e, "Too many entries"); | ||
} | ||
it.close(); | ||
|
||
// But with settings... | ||
it = MAPPER.readerFor(StringPair.class) | ||
.with(schema) | ||
.with(CsvParser.Feature.IGNORE_TRAILING_UNMAPPABLE) | ||
.readValues(INPUT); | ||
|
||
pair = it.nextValue(); | ||
assertEquals("a", pair.first); | ||
assertEquals("b", pair.second); | ||
|
||
pair = it.nextValue(); | ||
assertEquals("d", pair.first); | ||
assertEquals("e", pair.second); | ||
|
||
pair = it.nextValue(); | ||
assertEquals("f", pair.first); | ||
assertEquals("g", pair.second); | ||
|
||
assertFalse(it.hasNextValue()); | ||
|
||
it.close(); | ||
} | ||
} |