-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
66bfe66
commit 436c309
Showing
3 changed files
with
67 additions
and
10 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
50 changes: 50 additions & 0 deletions
50
src/test/java/com/fasterxml/jackson/databind/seq/ReadRecoveryTest.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,50 @@ | ||
package com.fasterxml.jackson.databind.seq; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.seq.ReadValuesTest.Bean; | ||
|
||
/** | ||
* Tests to verify aspects of error recover for reading using | ||
* iterator. | ||
*/ | ||
public class ReadRecoveryTest extends BaseMapTest | ||
{ | ||
static class Bean { | ||
public int a; | ||
|
||
@Override public String toString() { return "{Bean, a="+a+"}"; } | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests; root-level value sequences via Mapper | ||
/********************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
public void testRootBeans() throws Exception | ||
{ | ||
final String JSON = aposToQuotes("{'a':3} {'b':5}"); | ||
MappingIterator<Bean> it = MAPPER.reader(Bean.class).readValues(JSON); | ||
// First one should be fine | ||
assertTrue(it.hasNextValue()); | ||
Bean bean = it.nextValue(); | ||
assertEquals(3, bean.a); | ||
// but second one not | ||
try { | ||
bean = it.nextValue(); | ||
fail("Should not have succeeded"); | ||
} catch (JsonMappingException e) { | ||
verifyException(e, "Unrecognized field"); | ||
} | ||
// 24-Mar-2015, tatu: With 2.5, best we can do is to avoid infinite loop; | ||
// also, since the next token is END_OBJECT, will produce empty Object | ||
assertTrue(it.hasNextValue()); | ||
bean = it.nextValue(); | ||
assertEquals(0, bean.a); | ||
// and we should be done now | ||
assertFalse(it.hasNextValue()); | ||
it.close(); | ||
} | ||
} |