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

Boolean Coercion Mapping Feature #31

Open
geoffreywiseman opened this issue Nov 30, 2018 · 1 comment
Open

Boolean Coercion Mapping Feature #31

geoffreywiseman opened this issue Nov 30, 2018 · 1 comment

Comments

@geoffreywiseman
Copy link

I'd love to have a separate mapping feature disable to coercion of numbers to booleans without disabling a bunch of other scalar features.

If someone supplies a numeric string like "800" that I'm mapping to an integer field, I'm happy for Jackson to coerce the value to 800.

On the other hand, if someone supplies "isOrganization": 12, I don't want that to turn into true, because I suspect that 12 wasn't intended as a boolean value, that there's some other kind of mapping problem going on.

To be honest, I'm even ok with the 0/1 boolean mapping, I just don't want other numbers coerced to boolean, because I'm wary of it masking problems.

@cowtowncoder
Copy link
Member

I think this is doable for 3.x, with lenient property of @JsonFormat (and matching configOverrides).

Then again I wonder if it'd make sense to consider more generic approach to allowing coercion, something pluggable externally. And probably also tightening default settings to maybe only allow:

  1. strict handling: only allow boolean json value (and null possibly, depending on null-settings)
  2. lenient handling, default: allow Strings ("true", "false"), integers 0 and 1. -- String part may be challenging as I expect there to be no end to requests for other alternatives (case-insensitive, "t"/"f" etc etc).

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

No branches or pull requests

2 participants