Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 5, 2024
2 parents 3208593 + 7140de6 commit 193c875
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ a pure JSON library.

#1145: `JsonPointer.appendProperty(String)` does not escape the property name
(reported by Robert E)
#1149: Add `JsonParser.getNumberTypeFP()`
#1157: Use fast parser (FDP) for large `BigDecimal`s (500+ chars)
(contributed by @pjfanning)
#1169: `ArrayIndexOutOfBoundsException` for specific invalid content,
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/tools/jackson/core/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,44 @@ public enum NumberType {
INT, LONG, BIG_INTEGER, FLOAT, DOUBLE, BIG_DECIMAL
}

/**
* Enumeration of possible physical Floating-Point types that
* underlying format uses. Used to indicate most accurate (and
* efficient) representation if known (if not known,
* {@link NumberTypeFP#UNKNOWN} is used).
*/
public enum NumberTypeFP {
/**
* Special "mini-float" that some binary formats support.
*/
FLOAT16,

/**
* Standard IEEE-754 single-precision 32-bit binary value
*/
FLOAT32,

/**
* Standard IEEE-754 double-precision 64-bit binary value
*/
DOUBLE64,

/**
* Unlimited precision, decimal (10-based) values
*/
BIG_DECIMAL,

/**
* Constant used when type is not known, or there is no specific
* type to match: most commonly used for textual formats like JSON
* where representation does not necessarily have single easily detectable
* optimal representation (for example, value {@code 0.1} has no
* exact binary representation whereas {@code 0.25} has exact representation
* in every binary type supported)
*/
UNKNOWN;
}

/**
* Set of default {@link StreamReadCapability}ies enabled: usable as basis
* for format-specific instances or placeholder if non-null instance needed.
Expand Down Expand Up @@ -988,6 +1026,16 @@ public Boolean nextBooleanValue() throws JacksonException {
*/
public abstract NumberType getNumberType();

/**
* If current token is of type
* {@link JsonToken#VALUE_NUMBER_FLOAT}, returns
* one of {@link NumberTypeFP} constants; otherwise returns
* {@link NumberTypeFP#UNKNOWN}.
*
* @return Type of current number, if parser points to numeric token; {@code null} otherwise
*/
public abstract NumberTypeFP getNumberTypeFP();

/**
* Numeric accessor that can be called when the current
* token is of type {@link JsonToken#VALUE_NUMBER_INT} and
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/tools/jackson/core/base/ParserMinimalBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.math.BigInteger;

import tools.jackson.core.*;
import tools.jackson.core.JsonParser.NumberTypeFP;
import tools.jackson.core.exc.InputCoercionException;
import tools.jackson.core.exc.StreamReadException;
import tools.jackson.core.exc.UnexpectedEndOfInputException;
Expand Down Expand Up @@ -530,6 +531,11 @@ public int getText(Writer writer) throws JacksonException
// public abstract Number getNumberValue();
// public abstract NumberType getNumberType();

@Override
public NumberTypeFP getNumberTypeFP() {
return NumberTypeFP.UNKNOWN;
}

@Override
public Number getNumberValueExact() throws InputCoercionException {
return getNumberValue();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tools/jackson/core/util/JsonParserDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public JsonParser skipChildren() throws JacksonException {
@Override
public NumberType getNumberType() { return delegate.getNumberType(); }

@Override
public NumberTypeFP getNumberTypeFP() { return delegate.getNumberTypeFP(); }

@Override
public Number getNumberValue() throws InputCoercionException { return delegate.getNumberValue(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private void _testSimpleInt(int EXP_I, int mode)
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(JsonParser.NumberType.INT, p.getNumberType());
assertEquals(JsonParser.NumberTypeFP.UNKNOWN, p.getNumberTypeFP());
assertTrue(p.isExpectedNumberIntToken());
assertEquals(""+EXP_I, p.getText());

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/tools/jackson/core/util/TestDelegates.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import tools.jackson.core.*;
import tools.jackson.core.JsonParser.NumberType;
import tools.jackson.core.JsonParser.NumberTypeFP;
import tools.jackson.core.json.JsonFactory;

import static org.junit.Assert.assertArrayEquals;
Expand Down Expand Up @@ -181,6 +182,7 @@ public void testParserDelegate() throws IOException
assertFalse(del.isNaN());
assertTrue(del.isExpectedNumberIntToken());
assertEquals(NumberType.INT, del.getNumberType());
assertEquals(NumberTypeFP.UNKNOWN, del.getNumberTypeFP());
assertEquals(Integer.valueOf(1), del.getNumberValue());
assertNull(del.getEmbeddedObject());

Expand Down

0 comments on commit 193c875

Please sign in to comment.