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

Add test to verify that deserialization of sub type doesn't wrongly use BigDecimal #4138

Closed
1 task done
richturner opened this issue Oct 2, 2023 · 1 comment
Closed
1 task done
Labels
2.16 Issues planned for 2.16

Comments

@richturner
Copy link

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

New issue created from comment in #3251 (which seems related).

Deserializing JSON with floating point numbers will incorrectly use BigDecimal instead of Double when using sub types (even though DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS is false).

This bug is fixed in 2.15.2 but is present in the mentioned version (2.14.3) but a test should be added to prevent future regression if this fix was not deliberate.

I can also confirm the value of @JsonTypeInfo#include does not affect this behaviour.

Version Information

2.14.3

Reproduction

Subtype class definition

@JsonTypeInfo(property = "type", use = JsonTypeInfo.Id.NAME)
@JsonSubTypes({
    @JsonSubTypes.Type(ValueTest.ValueTest1.class)
})
public class ValueTest {

    @JsonTypeName("valueTest1")
    public static class ValueTest1 extends ValueTest {
        Object[] allowedValues;

        @JsonCreator
        protected ValueTest1() {
        }

        public ValueTest1(Object... allowedValues) {
            this.allowedValues = allowedValues;
        }

        public Object[] getAllowedValues() {
            return allowedValues;
        }
    }
}

JSON string to deserialize

JSON.readValue("{\"allowedValues\": [ 1.5, 2.5 ], \"type\": \"valueTest1\"}", ValueTest.class)

Result

Hydrated ValueTest instance will have BigDecimal objects in the allowedValues property.

Expected behavior

Hydrated ValueTest instance should contain Double objects unless DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS is true

Additional context

No response

@richturner richturner added the to-evaluate Issue that has been received but not yet evaluated label Oct 2, 2023
@cowtowncoder cowtowncoder added 2.16 Issues planned for 2.16 and removed to-evaluate Issue that has been received but not yet evaluated labels Oct 3, 2023
@cowtowncoder
Copy link
Member

Added test based on suggestion; passes for 2.16.0-SNAPSHOT and should guard against regression now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.16 Issues planned for 2.16
Projects
None yet
Development

No branches or pull requests

2 participants