Skip to content

Commit

Permalink
Fix #671
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 27, 2021
1 parent 5440887 commit 084865d
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 90 deletions.
9 changes: 5 additions & 4 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ JSON library.
3.0.0 (not yet released)

#378: Change default for `TokenStreamFactory.Feature.INTERN_FIELD_NAMES` to `false`
#402: Remove dataformat-auto-detection functionality
#411: Rename `JsonStreamContext` as `TokenStreamContext`
#413: Remove `ObjectCodec`: replace with `ObjectWriteContext` / `ObjectReadContext`
#432: Add new `TreeNode` subtypes: `ArrayTreeNode`, `ObjectTreeNode`
#433: Add Builder pattern for creating configured Stream factories
#456: Add `JsonParser.readAsValue(ResolvedType)`
#467: Create `JsonReadFeature` to move JSON-specific `JsonParser.Feature`s to
#481: Create `JsonWriteFeature` to move JSON-specific `JsonGenerator.Feature`s to
#492: Ensure primitive type names in error message enclosed in backticks
#495: Create `StreamReadFeature` to move non-json specific `JsonParser.Feature`s to
#496: Create `StreamWriteFeature` to take over non-json-specific `JsonGenerator.Feature`s
#551: Remove `JsonGenerator.setPrettyPrinter()` from 3.0
#670: Replace references to "field" in `JsonGenerator`, `JsonParser` method names with "property"
#671: Replace `getCurrentLocation()`/`getTokenLocation()` with
`currentLocation()`/`currentTokenLocation()`
- Rename `JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT` as `AUTO_CLOSE_CONTENT`
- Add `TreeCodec.nullNode()`, `TreeNode.isNull()` methods
- Change the way `JsonLocation.NA` is included in exception messages
8 changes: 6 additions & 2 deletions src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ protected JsonGenerator() { }
*<p>
* In general use of this accessor should be considered as
* "last effort", i.e. only used if no other mechanism is applicable.
*<p>
* NOTE: was named {@code getOutputTarget()} in Jackson 2.x.
*
* @return Output target this generator was configured with
*/
public abstract Object getOutputTarget();
public abstract Object streamWriteTarget();

/**
* Method for verifying amount of content that is buffered by generator
Expand All @@ -111,11 +113,13 @@ protected JsonGenerator() { }
* {@code char} for {@link java.io.Writer}),
* but may differ if buffering is done before encoding.
* Default JSON-backed implementations do use matching units.
*<p>
* NOTE: was named {@code getOutputBuffered()} in Jackson 2.x.
*
* @return Amount of content buffered in internal units, if amount known and
* accessible; -1 if not accessible.
*/
public abstract int getOutputBuffered();
public abstract int streamWriteOutputBuffered();

/**
* Helper method, usually equivalent to:
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/fasterxml/jackson/core/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ protected JsonParser() { }
* return {@link JsonLocation#NA} due to not having access
* to input location information (when delegating actual decoding work
* to other library)
*<p>
* NOTE: was named {@code getTokenLocation()} in Jackson 2.x.
*
* @return Starting location of the token parser currently points to
*/
public abstract JsonLocation getTokenLocation();
public abstract JsonLocation currentTokenLocation();

/**
* Method that returns location of the last processed character;
Expand Down Expand Up @@ -167,10 +169,12 @@ protected JsonParser() { }
*<p>
* In general use of this accessor should be considered as
* "last effort", i.e. only used if no other mechanism is applicable.
*<p>
* NOTE: was named {@code getInputSource()} in Jackson 2.x.
*
* @return Input source this parser was configured with
*/
public abstract Object getInputSource();
public abstract Object streamReadSource();

/*
/**********************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public int releaseBuffered(Writer w) throws JacksonException {
return count;
}

@Override public Object getInputSource() { return _reader; }
@Override public Object streamReadSource() { return _reader; }

protected char getNextChar(String eofMsg, JsonToken forToken) throws JacksonException {
if (_inputPtr >= _inputEnd) {
Expand Down Expand Up @@ -2867,7 +2867,7 @@ protected byte[] _decodeBase64(Base64Variant b64variant) throws JacksonException
*/

@Override
public JsonLocation getTokenLocation()
public JsonLocation currentTokenLocation()
{
if (_currToken == JsonToken.PROPERTY_NAME) {
long total = _currInputProcessed + (_nameStartOffset-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public int releaseBuffered(OutputStream out) {
}

@Override
public Object getInputSource() {
public Object streamReadSource() {
return _inputData;
}

Expand Down Expand Up @@ -2903,7 +2903,7 @@ protected final byte[] _decodeBase64(Base64Variant b64variant) throws IOExceptio
*/

@Override
public JsonLocation getTokenLocation() {
public JsonLocation currentTokenLocation() {
// 03-Jan-2020, tatu: Should probably track this, similar to how
// streaming parsers do it, but... not done yet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ public JsonGenerator setCharacterEscapes(CharacterEscapes esc)
*/

@Override
public Object getOutputTarget() {
public Object streamWriteTarget() {
return _outputStream;
}

@Override
public int getOutputBuffered() {
public int streamWriteOutputBuffered() {
// Assuming tail is always valid, set to 0 on close
return _outputTail;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public int releaseBuffered(OutputStream out) throws JacksonException
}

@Override
public Object getInputSource() {
public Object streamReadSource() {
return _inputStream;
}

Expand Down Expand Up @@ -4097,7 +4097,7 @@ protected final byte[] _decodeBase64(Base64Variant b64variant) throws JacksonExc

// As per [core#108], must ensure we call the right method
@Override
public JsonLocation getTokenLocation()
public JsonLocation currentTokenLocation()
{
if (_currToken == JsonToken.PROPERTY_NAME) {
long total = _currInputProcessed + (_nameStartOffset-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public JsonGenerator setCharacterEscapes(CharacterEscapes esc)
*/

@Override
public Object getOutputTarget() {
public Object streamWriteTarget() {
return _writer;
}

@Override
public int getOutputBuffered() {
public int streamWriteOutputBuffered() {
// Assuming tail and head are kept but... trust and verify:
int len = _outputTail - _outputHead;
return Math.max(0, len);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ protected void _releaseBuffers() throws JacksonException
}

@Override
public Object getInputSource() {
public Object streamReadSource() {
// since input is "pushed", to traditional source...
return null;
}
Expand Down Expand Up @@ -336,7 +336,7 @@ public JsonLocation currentLocation()
}

@Override
public JsonLocation getTokenLocation()
public JsonLocation currentTokenLocation()
{
return new JsonLocation(_getSourceReference(),
_tokenInputTotal, -1L, _tokenInputRow, _tokenInputCol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public void assignCurrentValue(Object v) {

@Override public FormatSchema getSchema() { return delegate.getSchema(); }
@Override public Version version() { return delegate.version(); }
@Override public Object getOutputTarget() { return delegate.getOutputTarget(); }
@Override public int getOutputBuffered() { return delegate.getOutputBuffered(); }
@Override public Object streamWriteTarget() { return delegate.streamWriteTarget(); }
@Override public int streamWriteOutputBuffered() { return delegate.streamWriteOutputBuffered(); }

/*
/**********************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public JsonParserDelegate(JsonParser d) {

// // // Public API, input source, location access

@Override public JsonLocation getTokenLocation() { return delegate.getTokenLocation(); }
@Override public JsonLocation currentTokenLocation() { return delegate.currentTokenLocation(); }
@Override public JsonLocation currentLocation() { return delegate.currentLocation(); }
@Override public Object getInputSource() { return delegate.getInputSource(); }
@Override public Object streamReadSource() { return delegate.streamReadSource(); }

@Override
public Object currentValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void testSingleMatchFilteringWithPath() throws Exception
);

// Hmmh. Should we get access to eventual target?
assertSame(w, gen.getOutputTarget());
assertSame(w, gen.streamWriteTarget());
assertNotNull(gen.getFilterContext());
assertSame(filter, gen.getFilter());

Expand All @@ -203,7 +203,7 @@ public void testSingleMatchFilteringWithPathSkippedArray() throws Exception
);

// Hmmh. Should we get access to eventual target?
assertSame(w, gen.getOutputTarget());
assertSame(w, gen.streamWriteTarget());
assertNotNull(gen.getFilterContext());
assertSame(filter, gen.getFilter());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void _testUTF8BomOk(int offset, int readSize) throws Exception
* "out of stream" (not part of input).
*/

JsonLocation loc = p.parser().getTokenLocation();
JsonLocation loc = p.parser().currentTokenLocation();
// so if BOM was consider in-stream (part of input), this should expect 3:
// (NOTE: this is location for START_ARRAY token, now)
assertEquals(-1, loc.getCharOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public void testLocationOffsets() throws Exception
feeder.feedInput(input, 2, 3);
assertEquals(JsonToken.START_ARRAY, parser.nextToken());
assertEquals(1, parser.currentLocation().getByteOffset());
assertEquals(1, parser.getTokenLocation().getByteOffset());
assertEquals(1, parser.currentTokenLocation().getByteOffset());
assertEquals(1, parser.currentLocation().getLineNr());
assertEquals(1, parser.getTokenLocation().getLineNr());
assertEquals(1, parser.currentTokenLocation().getLineNr());
assertEquals(2, parser.currentLocation().getColumnNr());
assertEquals(1, parser.getTokenLocation().getColumnNr());
assertEquals(1, parser.currentTokenLocation().getColumnNr());

feeder.feedInput(input, 0, 1);
assertEquals(JsonToken.START_ARRAY, parser.nextToken());
assertEquals(2, parser.currentLocation().getByteOffset());
assertEquals(2, parser.getTokenLocation().getByteOffset());
assertEquals(2, parser.currentTokenLocation().getByteOffset());
assertEquals(1, parser.currentLocation().getLineNr());
assertEquals(1, parser.getTokenLocation().getLineNr());
assertEquals(1, parser.currentTokenLocation().getLineNr());
assertEquals(3, parser.currentLocation().getColumnNr());
assertEquals(2, parser.getTokenLocation().getColumnNr());
assertEquals(2, parser.currentTokenLocation().getColumnNr());
parser.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testAsyncParerDefaults() throws IOException
JsonParser p = r.parser();

assertTrue(p.canParseAsync());
assertNull(p.getInputSource());
assertNull(p.streamReadSource());
assertEquals(-1, p.releaseBuffered(new StringWriter()));
assertEquals(0, p.releaseBuffered(new ByteArrayOutputStream()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void assertCurrentLocation(JsonParser p, LocData loc)

private void assertTokenLocation(JsonParser p, LocData loc)
{
assertLocation(p.getTokenLocation(), loc);
assertLocation(p.currentTokenLocation(), loc);
}

private void assertLocation(JsonLocation pLoc, LocData loc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void assertCurrentLocation(JsonParser p, LocData loc)

private void assertTokenLocation(JsonParser p, LocData loc)
{
assertLocation(p.getTokenLocation(), loc);
assertLocation(p.currentTokenLocation(), loc);
}

private void assertLocation(JsonLocation pLoc, LocData loc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ private void _testOffsetInArrays(boolean useBytes) throws Exception
p = useBytes ? JSON_F.createParser(ObjectReadContext.empty(), DOC.getBytes("UTF-8"))
: JSON_F.createParser(ObjectReadContext.empty(), DOC.toCharArray());
assertToken(JsonToken.START_ARRAY, p.nextToken());
_assertLocation(useBytes, p.getTokenLocation(), 2L, 1, 3);
_assertLocation(useBytes, p.currentTokenLocation(), 2L, 1, 3);
_assertLocation(useBytes, p.currentLocation(), 3L, 1, 4);

assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
_assertLocation(useBytes, p.getTokenLocation(), 3L, 1, 4);
_assertLocation(useBytes, p.currentTokenLocation(), 3L, 1, 4);
assertEquals(10, p.getIntValue()); // just to ensure read proceeds to end
// 2-digits so
_assertLocation(useBytes, p.currentLocation(), 5L, 1, 6);

assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
_assertLocation(useBytes, p.getTokenLocation(), 7L, 1, 8);
_assertLocation(useBytes, p.currentTokenLocation(), 7L, 1, 8);
assertEquals(251, p.getIntValue()); // just to ensure read proceeds to end
_assertLocation(useBytes, p.currentLocation(), 10L, 1, 11);

assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
_assertLocation(useBytes, p.getTokenLocation(), 15L, 2, 4);
_assertLocation(useBytes, p.currentTokenLocation(), 15L, 2, 4);
assertEquals(3, p.getIntValue());
_assertLocation(useBytes, p.currentLocation(), 16L, 2, 5);

assertToken(JsonToken.END_ARRAY, p.nextToken());
_assertLocation(useBytes, p.getTokenLocation(), 18L, 2, 7);
_assertLocation(useBytes, p.currentTokenLocation(), 18L, 2, 7);
_assertLocation(useBytes, p.currentLocation(), 19L, 2, 8);

p.close();
Expand Down
Loading

0 comments on commit 084865d

Please sign in to comment.