Skip to content

Commit c3fa50f

Browse files
committed
Merge branch '2.12'
2 parents 963c876 + 90379ff commit c3fa50f

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ JSON library.
2323
#627: Add `JsonParser.isExpectedNumberIntToken()` convenience method
2424
#630: Add `StreamWriteCapability` for further format-based/format-agnostic
2525
handling improvements
26+
#631: Add `JsonParser.getNumberValueExact()` to allow precision-retaining buffering
2627
- Deprecate `JsonParser.getCurrentTokenId()` (use `#currentTokenId()` instead)
2728

2829
2.11.1 (25-Jun-2020)

src/main/java/com/fasterxml/jackson/core/JsonParser.java

+31
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,40 @@ public int getText(Writer writer) throws IOException, UnsupportedOperationExcept
819819
* all kinds of numeric values. It will return the optimal
820820
* (simplest/smallest possible) wrapper object that can
821821
* express the numeric value just parsed.
822+
*
823+
* @return Numeric value of the current token in its most optimal
824+
* representation
825+
*
826+
* @throws IOException Problem with access: {@link JsonParseException} if
827+
* the current token is not numeric, or if decoding of the value fails
828+
* (invalid format for numbers); plain {@link IOException} if underlying
829+
* content read fails (possible if values are extracted lazily)
822830
*/
823831
public abstract Number getNumberValue() throws IOException;
824832

833+
/**
834+
* Method similar to {@link #getNumberValue} with the difference that
835+
* for floating-point numbers value returned may be {@link BigDecimal}
836+
* if the underlying format does not store floating-point numbers using
837+
* native representation: for example, textual formats represent numbers
838+
* as Strings (which are 10-based), and conversion to {@link java.lang.Double}
839+
* is potentially lossy operation.
840+
*<p>
841+
* Default implementation simply returns {@link #getNumberValue()}
842+
*
843+
* @return Numeric value of the current token using most accurate representation
844+
*
845+
* @throws IOException Problem with access: {@link JsonParseException} if
846+
* the current token is not numeric, or if decoding of the value fails
847+
* (invalid format for numbers); plain {@link IOException} if underlying
848+
* content read fails (possible if values are extracted lazily)
849+
*
850+
* @since 2.12
851+
*/
852+
public Number getNumberValueExact() throws IOException {
853+
return getNumberValue();
854+
}
855+
825856
/**
826857
* If current token is of type
827858
* {@link JsonToken#VALUE_NUMBER_INT} or

src/main/java/com/fasterxml/jackson/core/base/ParserBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public Number getNumberValue() throws IOException
482482
}
483483
return _numberDouble;
484484
}
485-
485+
486486
@Override
487487
public NumberType getNumberType() throws IOException
488488
{

src/main/java/com/fasterxml/jackson/core/util/JsonParserDelegate.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,15 @@ public JsonParser skipChildren() throws IOException {
206206
@Override
207207
public Number getNumberValue() throws IOException { return delegate.getNumberValue(); }
208208

209+
@Override
210+
public Number getNumberValueExact() throws IOException { return delegate.getNumberValueExact(); }
211+
209212
/*
210213
/**********************************************************************
211214
/* Public API, access to token information, coercion/conversion
212215
/**********************************************************************
213216
*/
214-
217+
215218
@Override public int getValueAsInt() throws IOException { return delegate.getValueAsInt(); }
216219
@Override public int getValueAsInt(int defaultValue) throws IOException { return delegate.getValueAsInt(defaultValue); }
217220
@Override public long getValueAsLong() throws IOException { return delegate.getValueAsLong(); }

0 commit comments

Comments
 (0)