Skip to content

Allow preventing "Enum from integer" coercion using new CoercionConfig system #2903

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

Closed
cowtowncoder opened this issue Oct 24, 2020 · 0 comments
Labels
coercion-config Issue related to 2.12 added "CoercionConfig"
Milestone

Comments

@cowtowncoder
Copy link
Member

(follow-up for #2750 )

One coercion that has been problematic (and configuration setting was been requested for) is that of accepting integer value, assumed to be used as the index of Enum. While this can be efficient representation it can be brittle (as index can change if Enums are reordered in class definition) and cause invalid content to be accepted.

Configuration should probably be of form:

    // to prevent for ALL enums:
    mapper.coercionConfigFor(LogicalType.Enum)
        .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
    // or individual type
    mapper.coercionConfigFor(MyEnum.class)
        .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)

Note, too, that this should allow alternatives of AsEmpty (default value, if specified, otherwise... null?) and AsNull.

@cowtowncoder cowtowncoder added to-evaluate Issue that has been received but not yet evaluated 2.12 coercion-config Issue related to 2.12 added "CoercionConfig" and removed to-evaluate Issue that has been received but not yet evaluated labels Oct 24, 2020
cowtowncoder added a commit that referenced this issue Oct 24, 2020
@cowtowncoder cowtowncoder added this to the 2.12.0-rc2 milestone Oct 25, 2020
cowtowncoder added a commit that referenced this issue Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coercion-config Issue related to 2.12 added "CoercionConfig"
Projects
None yet
Development

No branches or pull requests

1 participant