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

Prevent use of quoted number (index) for Enum deserialization via MapperFeature.ALLOW_COERCION_OF_SCALARS #1690

Closed
wants to merge 1 commit into from
Closed

Conversation

magdel
Copy link

@magdel magdel commented Jul 5, 2017

Just want to make option to restrict default ability to deserialize any number string as enum value if it is in its ordinal range

@f0y
Copy link

f0y commented Jul 5, 2017

Existing behaviour of enum deserialization is absolutely unexpеcted.
Why does someone want to deserialize string as enum ordinal? There is json integer type for that case.

@cowtowncoder
Copy link
Member

cowtowncoder commented Jul 14, 2017

@f0y When using XML, for example, there is no way to reliably detect numbers. Or when using properties. Some (many?) scripting languages have loose type system. In general, every loose handling feature is based on someone requesting (and presumably needing) it.

Specific request to add this coercion (along with use of numeric index) was #149.

I am not saying that users should use JSON Strings to contain integer values, but rather just that if the use case is such that one tries to figure out meaning for a String that does not map to known textual values, considering possibility of index value is a viable choice.

But I'll see if any of DeserializationFeatures could allow easy configurability here. Preventing such coercion itself is pretty easy of course; I just do not want to break existing use cases.

@cowtowncoder cowtowncoder added 2.9 and removed ACTIVE labels Jul 14, 2017
@cowtowncoder cowtowncoder modified the milestones: 2.2, 2.9.0 Jul 19, 2017
@cowtowncoder cowtowncoder changed the title Ability to disable string enum values deserialization as ordinal number Prevent use of quoted number (index) for Enum deserialization via MapperFeature.ALLOW_COERCION_OF_SCALARS Jul 19, 2017
@cowtowncoder
Copy link
Member

Modified deserializer to check for MapperFeature.ALLOW_COERCION_OF_SCALARS, and if that is disabled (default is enabled), will not consider quoted int value (that is, JSON String containing number) as an index.

@cowtowncoder
Copy link
Member

Quick note: fix itself is similar to PR -- thank you for submitting it! -- but I try to avoid adding too many specific features at this point (both to keep API bit smaller, and since there are limits for number; beyond 32 need to change impl a bit).

@f0y
Copy link

f0y commented Jul 20, 2017

Thank you for submitting the fix!

@magdel
Copy link
Author

magdel commented Aug 1, 2017

Great!

@cowtowncoder
Copy link
Member

Fwtw, 2.9.0 is now finally released!

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

Successfully merging this pull request may close these issues.

3 participants