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

Coercion Config and ALLOW_COERCION_OF_SCALARS settings do not prevent integer to java.util.Date conversion #4952

Open
1 task done
ivamly opened this issue Feb 6, 2025 · 1 comment
Labels
2.19 Issues planned at 2.19 or later

Comments

@ivamly
Copy link

ivamly commented Feb 6, 2025

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Even when the ALLOW_COERCION_OF_SCALARS feature is explicitly disabled and CoercionAction.Fail is set for integer values to java.util.Date, the system does not throw an error during the deserialization process when an integer is being converted into a java.util.Date.

Version Information

2.18.2

Reproduction

You can find a minimal example to reproduce this issue in the following repository

Expected behavior

When an integer is provided as input, the conversion to java.util.Date should fail and throw a MismatchedInputException or a similar exception.

Additional context

I might be missing something in my setup, or maybe there's a better way to configure this. If you have any tips or ideas on how to make this work the way I expect, I'd really appreciate it!

@ivamly ivamly added the to-evaluate Issue that has been received but not yet evaluated label Feb 6, 2025
@cowtowncoder
Copy link
Member

Adding the important piece from project: configuration

        ObjectMapper mapper = new ObjectMapper();
        mapper.coercionConfigFor(Date.class)
                .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail);
        mapper.coercionConfigFor(LogicalType.DateTime)
                .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail);

which indeed could be expected to prevent coercion.

@cowtowncoder cowtowncoder added 2.19 Issues planned at 2.19 or later and removed to-evaluate Issue that has been received but not yet evaluated labels Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.19 Issues planned at 2.19 or later
Projects
None yet
Development

No branches or pull requests

2 participants