Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3624 ALLOW_COERCION_OF_SCALARS allows int->float coercion #3625

Merged
merged 1 commit into from
Oct 13, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,14 @@ public CoercionAction findCoercion(DeserializationConfig config,
// scalar for this particular purpose
final boolean baseScalar = _isScalarType(targetType);

if (baseScalar) {
// Default for setting in 2.x is true
if (!config.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS)) {
if (baseScalar
// Default for setting in 2.x is true
&& !config.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS)
// Coercion from integer-shaped data into a floating point type is not banned by the
// ALLOW_COERCION_OF_SCALARS feature because '1' is a valid JSON representation of
// '1.0' in a way that other types of coercion do not satisfy.
&& (targetType != LogicalType.Float || inputShape != CoercionInputShape.Integer)) {
return CoercionAction.Fail;
}
}

if (inputShape == CoercionInputShape.EmptyString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
Expand Down Expand Up @@ -34,6 +35,10 @@ public class CoerceIntToFloatTest extends BaseMapTest
cfg.setCoercion(CoercionInputShape.Integer, CoercionAction.AsEmpty))
.build();

private final ObjectMapper LEGACY_SCALAR_COERCION_FAIL = jsonMapperBuilder()
.disable(MapperFeature.ALLOW_COERCION_OF_SCALARS)
.build();

public void testDefaultIntToFloatCoercion() throws JsonProcessingException
{
assertSuccessfulIntToFloatConversionsWith(DEFAULT_MAPPER);
Expand Down Expand Up @@ -115,6 +120,11 @@ public void testCoerceConfigToFail() throws JsonProcessingException
_verifyCoerceFail(MAPPER_TO_FAIL, BigDecimal.class, "73455342");
}

public void testLegacyConfiguration() throws JsonProcessingException
{
assertSuccessfulIntToFloatConversionsWith(LEGACY_SCALAR_COERCION_FAIL);
}

/*
/********************************************************
/* Helper methods
Expand Down