Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Versions: 3.x (for earlier see VERSION-2.x)
=== Releases ===
------------------------------------------------------------------------

Not yet released

#5319: `TreeTraversingParser` does not respect `DeserializationFeature.ACCEPT_FLOAT_AS_INT`
(reported by @Artur)

3.0.0-rc10 (19-Sep-2025)

#5272: Replace `ObjectMapper.getRegisteredModuleIds()` (2.x) with
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/tools/jackson/databind/node/BigIntegerNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,20 @@ public Optional<BigDecimal> decimalValueOpt() {
*/

@Override
protected int _asIntValueUnchecked() {
public short _asShortValueUnchecked() {
return _value.shortValue();
}

@Override
public int _asIntValueUnchecked() {
return _value.intValue();
}

@Override
public long _asLongValueUnchecked() {
return _value.longValue();
}

@Override
protected float _asFloatValueUnchecked() {
return _value.floatValue();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tools/jackson/databind/node/DecimalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ public OptionalDouble asDoubleOpt() {
*/

@Override
protected short _asShortValueUnchecked() {
public short _asShortValueUnchecked() {
return _value.shortValue();
}

@Override
protected int _asIntValueUnchecked() {
public int _asIntValueUnchecked() {
return _value.intValue();
}

@Override
protected long _asLongValueUnchecked() {
public long _asLongValueUnchecked() {
return _value.longValue();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tools/jackson/databind/node/DoubleNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ public OptionalDouble asDoubleOpt() {
*/

@Override
protected short _asShortValueUnchecked() {
public short _asShortValueUnchecked() {
return (short) _value;
}

@Override
protected int _asIntValueUnchecked() {
public int _asIntValueUnchecked() {
return (int) _value;
}

@Override
protected long _asLongValueUnchecked() {
public long _asLongValueUnchecked() {
return (long) _value;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tools/jackson/databind/node/FloatNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ public OptionalDouble asDoubleOpt() {
*/

@Override
protected short _asShortValueUnchecked() {
public short _asShortValueUnchecked() {
return (short) _value;
}

@Override
protected int _asIntValueUnchecked() {
public int _asIntValueUnchecked() {
return (int) _value;
}

@Override
protected long _asLongValueUnchecked() {
public long _asLongValueUnchecked() {
return (long) _value;
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/tools/jackson/databind/node/IntNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,17 @@ public Optional<BigInteger> bigIntegerValueOpt() {
*/

@Override
protected int _asIntValueUnchecked() {
public short _asShortValueUnchecked() {
return (short) _value;
}

@Override
public long _asLongValueUnchecked() {
return _value;
}

@Override
public int _asIntValueUnchecked() {
return _value;
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/tools/jackson/databind/node/LongNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,19 @@ public Optional<BigInteger> bigIntegerValueOpt() {
*/

@Override
protected int _asIntValueUnchecked() {
public short _asShortValueUnchecked() {
return (short) _value;
}

@Override
public int _asIntValueUnchecked() {
return (int) _value;
}

@Override
public long _asLongValueUnchecked() {
return _value;
}

@Override
protected float _asFloatValueUnchecked() {
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/tools/jackson/databind/node/NumericFPNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,39 +329,12 @@ public Optional<BigDecimal> asDecimalOpt() {
return Optional.of(_asDecimalValueUnchecked());
}

/*
/**********************************************************************
/* NumericNode extensions
/**********************************************************************
*/

/*
/**********************************************************************
/* Abstract methods for sub-classes to implement
/**********************************************************************
*/

/**
* Method for sub-classes to implement; returns the underlying
* value as a {@code short} without any checks (wrt NaN or value range),
* so caller must ensure validity prior to calling
*/
protected abstract short _asShortValueUnchecked();

/**
* Method for sub-classes to implement; returns the underlying
* value as a {@code int} without any checks (wrt NaN or value range),
* so caller must ensure validity prior to calling
*/
protected abstract int _asIntValueUnchecked();

/**
* Method for sub-classes to implement; returns the underlying
* value as a {@code long} without any checks (wrt NaN or value range),
* so caller must ensure validity prior to calling
*/
protected abstract long _asLongValueUnchecked();

/**
* Method for sub-classes to implement; returns the underlying
* value as a {@link BigInteger} without any checks (wrt NaN), so caller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,10 @@ public boolean hasFractionalPart() {

/*
/**********************************************************************
/* Abstract methods for sub-classes
/* API extensions for sub-classes
/**********************************************************************
*/

protected abstract int _asIntValueUnchecked();

protected abstract float _asFloatValueUnchecked();

protected abstract double _asDoubleValueUnchecked();
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/tools/jackson/databind/node/NumericNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected final String _valueDesc() {

/*
/**********************************************************************
/* Extended API
/* Extended API, public methods
/**********************************************************************
*/

Expand Down Expand Up @@ -141,4 +141,31 @@ protected final String _valueDesc() {
* "not-a-number" (NaN) value.
*/
public abstract boolean isNaN();

/*
/**********************************************************************
/* Extended API, unsafe access methods
/**********************************************************************
*/

/**
* Method for sub-classes to implement; returns the underlying
* value as a {@code short} without any checks (wrt NaN or value range),
* so caller must ensure validity prior to calling
*/
public abstract short _asShortValueUnchecked();

/**
* Method for sub-classes to implement; returns the underlying
* value as a {@code int} without any checks (wrt NaN or value range),
* so caller must ensure validity prior to calling
*/
public abstract int _asIntValueUnchecked();

/**
* Method for sub-classes to implement; returns the underlying
* value as a {@code long} without any checks (wrt NaN or value range),
* so caller must ensure validity prior to calling
*/
public abstract long _asLongValueUnchecked();
}
12 changes: 11 additions & 1 deletion src/main/java/tools/jackson/databind/node/ShortNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,17 @@ public Optional<BigInteger> bigIntegerValueOpt() {
*/

@Override
protected int _asIntValueUnchecked() {
public short _asShortValueUnchecked() {
return _value;
}

@Override
public int _asIntValueUnchecked() {
return _value;
}

@Override
public long _asLongValueUnchecked() {
return _value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ public int getIntValue() throws InputCoercionException {
public int getValueAsInt()
{
final NumericNode node = (NumericNode) currentNumericNode(NR_INT);
if (node.canConvertToInt()) {
return node.intValue();
if (node.inIntRange()) {
return node._asIntValueUnchecked();
}
// !!! TODO: better defaulting/coercion?
return getIntValue();
Expand All @@ -328,13 +328,13 @@ public int getValueAsInt()
public int getValueAsInt(int defaultValue)
{
final NumericNode node = (NumericNode) currentNumericNode(NR_INT);
if (node.canConvertToInt()) {
return node.intValue();
if (node.inIntRange()) {
return node._asIntValueUnchecked();
}
// !!! TODO: better defaulting/coercion?
return defaultValue;
}

@Override
public long getLongValue() throws InputCoercionException {
final NumericNode node = (NumericNode) currentNumericNode(NR_LONG);
Expand All @@ -354,6 +354,28 @@ public long getLongValue() throws InputCoercionException {
return node.longValue();
}

@Override
public long getValueAsLong()
{
final NumericNode node = (NumericNode) currentNumericNode(NR_INT);
if (node.inLongRange()) {
return node._asLongValueUnchecked();
}
// !!! TODO: better defaulting/coercion?
return getLongValue();
}

@Override
public long getValueAsLong(long defaultValue)
{
final NumericNode node = (NumericNode) currentNumericNode(NR_INT);
if (node.inLongRange()) {
return node._asLongValueUnchecked();
}
// !!! TODO: better defaulting/coercion?
return defaultValue;
}

@Override
public Number getNumberValue() throws InputCoercionException {
return currentNumericNode(-1).numberValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import tools.jackson.databind.exc.InvalidFormatException;
import tools.jackson.databind.exc.MismatchedInputException;
import tools.jackson.databind.node.JsonNodeFactory;
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;
import tools.jackson.databind.type.LogicalType;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -84,7 +83,6 @@ public void testLegacyDoubleToIntCoercion() throws Exception
}

// [databind#5319]
@JacksonTestFailureExpected
@Test
public void testLegacyDoubleToIntCoercionJsonNodeToInteger() throws Exception
{
Expand All @@ -98,7 +96,6 @@ public void testLegacyDoubleToIntCoercionJsonNodeToInteger() throws Exception
}

// [databind#5319]
@JacksonTestFailureExpected
@Test
public void testLegacyDoubleToIntCoercionJsonNodeToLong() throws Exception
{
Expand All @@ -112,7 +109,6 @@ public void testLegacyDoubleToIntCoercionJsonNodeToLong() throws Exception
}

// [databind#5319]
//@JacksonTestFailureExpected
@Test
public void testLegacyDoubleToIntCoercionJsonNodeToBigInteger() throws Exception
{
Expand Down
Loading
Loading