Skip to content

Commit

Permalink
Fixed #733
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 25, 2015
1 parent 66bfe66 commit 436c309
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project: jackson-databind
#728: TypeFactory#_fromVariable returns unknownType() even though it has enough information
to provide a more specific type
(reported by jkochaniak@github)
#733: MappingIterator should move past errors or not return hasNext() == true
(reported by Lorrin N, lorrin@github)
- Improvement to handling of custom `ValueInstantiator` for delegating mode; no more NPE
if `getDelegateCreator()` returns null

Expand Down
25 changes: 15 additions & 10 deletions src/main/java/com/fasterxml/jackson/databind/MappingIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,22 @@ public T nextValue() throws IOException
return _throwNoSuchElement();
}
_hasNextChecked = false;
T result;

if (_updatedValue == null) {
result = _deserializer.deserialize(_parser, _context);
} else{
_deserializer.deserialize(_parser, _context, _updatedValue);
result = _updatedValue;

try {
if (_updatedValue == null) {
return _deserializer.deserialize(_parser, _context);
} else{
_deserializer.deserialize(_parser, _context, _updatedValue);
return _updatedValue;
}
} finally {
/* 24-Mar-2015, tatu: As per [#733], need to mark token consumed no
* matter what, to avoid infinite loop for certain failure cases.
* For 2.6 need to improve further.
*/
// Need to consume the token too
_parser.clearCurrentToken();
}
// Need to consume the token too
_parser.clearCurrentToken();
return result;
}

/**
Expand Down
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();
}
}

0 comments on commit 436c309

Please sign in to comment.