Skip to content

Commit

Permalink
Fix #563 (async parser, location for array values)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 19, 2019
1 parent ce70782 commit fc73bee
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion release-notes/CREDITS-2.x
Expand Up @@ -155,7 +155,7 @@ Doug Roper (htmldoug@github)
* Suggested #463: Ensure that `skipChildren()` of non-blocking `JsonParser` will throw
exception if not enough input
(2.9.6)
* Contributed test for #563: Async parser does not keep track of Array context properly
* Reported, Contributed test for #563: Async parser does not keep track of Array context properly
(2.10.0)
Alexander Eyers-Taylor (aeyerstaylor@github)
Expand Down
5 changes: 3 additions & 2 deletions release-notes/VERSION-2.x
Expand Up @@ -16,9 +16,10 @@ JSON library.

2.10.0.pr3 (16-Sep-2019)

#479: Improve thread-safety of buffer recycling to enable recycling again
for async parsing
#479: Improve thread-safety of buffer recycling
#561: Misleading exception for unquoted String parsing
#563: Async parser does not keep track of Array context properly
(reported by Doug R)

2.10.0.pr2 (31-Aug-2019)

Expand Down
Expand Up @@ -602,6 +602,9 @@ private final JsonToken _startValue(int ch) throws IOException
}
}
_updateTokenLocation();
// 17-Sep-2019, tatu: [core#563] Need to call this to update index within array
_parsingContext.expectComma();

if (ch == INT_QUOTE) {
return _startString();
}
Expand Down
@@ -1,8 +1,8 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.core.json.async;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.async.AsyncTestBase;
import com.fasterxml.jackson.core.json.async.NonBlockingJsonParser;
import com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper;

public class AsyncPointerFromContext563Test extends AsyncTestBase
{
Expand All @@ -11,11 +11,23 @@ public class AsyncPointerFromContext563Test extends AsyncTestBase
// [core#563]
public void testPointerWithAsyncParser() throws Exception
{
JsonParser p = JSON_F.createNonBlockingByteArrayParser();
final String SIMPLE = aposToQuotes("{'a':123,'array':[1,2,[3],5,{'obInArray':4}],"
+"'ob':{'first':[false,true],'second':{'sub':37}},'b':true}");
byte[] SIMPLE_BYTES = SIMPLE.getBytes("UTF-8");
((NonBlockingJsonParser) p).feedInput(SIMPLE_BYTES, 0, SIMPLE_BYTES.length);

_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 1000);
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 7);
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 3);
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 2);
_testPointerWithAsyncParser(SIMPLE_BYTES, 0, 1);

_testPointerWithAsyncParser(SIMPLE_BYTES, 20, 5);
_testPointerWithAsyncParser(SIMPLE_BYTES, 14, 1);
}

public void _testPointerWithAsyncParser(byte[] doc, int offset, int readSize) throws Exception
{
AsyncReaderWrapper p = asyncForBytes(JSON_F, readSize, doc, offset);

// by default should just get "empty"
assertSame(JsonPointer.empty(), p.getParsingContext().pathAsPointer());
Expand All @@ -24,6 +36,8 @@ public void testPointerWithAsyncParser() throws Exception
assertToken(JsonToken.START_OBJECT, p.nextToken());
assertSame(JsonPointer.empty(), p.getParsingContext().pathAsPointer());

assertEquals("", p.getParsingContext().pathAsPointer().toString());

assertToken(JsonToken.FIELD_NAME, p.nextToken()); // a
assertEquals("/a", p.getParsingContext().pathAsPointer().toString());

Expand Down Expand Up @@ -92,8 +106,8 @@ public void testPointerWithAsyncParser() throws Exception
assertToken(JsonToken.END_OBJECT, p.nextToken());
assertSame(JsonPointer.empty(), p.getParsingContext().pathAsPointer());

// note: wrapper maps to `null`, plain async-parser would give NOT_AVAILABLE
assertNull(p.nextToken());
p.close();

}
}
Expand Up @@ -7,6 +7,7 @@

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonParser.NumberType;
import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.core.JsonToken;

public abstract class AsyncReaderWrapper
Expand Down Expand Up @@ -53,6 +54,10 @@ public String currentName() throws IOException {

public abstract JsonToken nextToken() throws IOException;

public JsonStreamContext getParsingContext() {
return _streamReader.getParsingContext();
}

public int getIntValue() throws IOException { return _streamReader.getIntValue(); }
public long getLongValue() throws IOException { return _streamReader.getLongValue(); }
public float getFloatValue() throws IOException { return _streamReader.getFloatValue(); }
Expand Down

0 comments on commit fc73bee

Please sign in to comment.