Skip to content

Commit

Permalink
Fixed #631
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 10, 2020
1 parent b26d1af commit 90379ff
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ JSON library.
#627: Add `JsonParser.isExpectedNumberIntToken()` convenience method
#630: Add `StreamWriteCapability` for further format-based/format-agnostic
handling improvements
#631: Add `JsonParser.getNumberValueExact()` to allow precision-retaining buffering
- Deprecate `JsonParser.getCurrentTokenId()` (use `#currentTokenId()` instead)

2.11.1 (25-Jun-2020)
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,40 @@ public int getText(Writer writer) throws IOException, UnsupportedOperationExcept
* all kinds of numeric values. It will return the optimal
* (simplest/smallest possible) wrapper object that can
* express the numeric value just parsed.
*
* @return Numeric value of the current token in its most optimal
* representation
*
* @throws IOException Problem with access: {@link JsonParseException} if
* the current token is not numeric, or if decoding of the value fails
* (invalid format for numbers); plain {@link IOException} if underlying
* content read fails (possible if values are extracted lazily)
*/
public abstract Number getNumberValue() throws IOException;

/**
* Method similar to {@link #getNumberValue} with the difference that
* for floating-point numbers value returned may be {@link BigDecimal}
* if the underlying format does not store floating-point numbers using
* native representation: for example, textual formats represent numbers
* as Strings (which are 10-based), and conversion to {@link java.lang.Double}
* is potentially lossy operation.
*<p>
* Default implementation simply returns {@link #getNumberValue()}
*
* @return Numeric value of the current token using most accurate representation
*
* @throws IOException Problem with access: {@link JsonParseException} if
* the current token is not numeric, or if decoding of the value fails
* (invalid format for numbers); plain {@link IOException} if underlying
* content read fails (possible if values are extracted lazily)
*
* @since 2.12
*/
public Number getNumberValueExact() throws IOException {
return getNumberValue();
}

/**
* If current token is of type
* {@link JsonToken#VALUE_NUMBER_INT} or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public Number getNumberValue() throws IOException
}
return _numberDouble;
}

@Override
public NumberType getNumberType() throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,15 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
@Override
public Number getNumberValue() throws IOException { return delegate.getNumberValue(); }

@Override
public Number getNumberValueExact() throws IOException { return delegate.getNumberValueExact(); }

/*
/**********************************************************
/* Public API, access to token information, coercion/conversion
/**********************************************************
*/

@Override public int getValueAsInt() throws IOException { return delegate.getValueAsInt(); }
@Override public int getValueAsInt(int defaultValue) throws IOException { return delegate.getValueAsInt(defaultValue); }
@Override public long getValueAsLong() throws IOException { return delegate.getValueAsLong(); }
Expand All @@ -209,7 +212,7 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
@Override public boolean getValueAsBoolean(boolean defaultValue) throws IOException { return delegate.getValueAsBoolean(defaultValue); }
@Override public String getValueAsString() throws IOException { return delegate.getValueAsString(); }
@Override public String getValueAsString(String defaultValue) throws IOException { return delegate.getValueAsString(defaultValue); }

/*
/**********************************************************
/* Public API, access to token values, other
Expand Down

0 comments on commit 90379ff

Please sign in to comment.