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

Please add DeserializationFeature.ACCEPT_STRING_AS_BOOLEAN #2114

Closed
2 tasks done
eximius313 opened this issue Aug 17, 2018 · 4 comments
Closed
2 tasks done

Please add DeserializationFeature.ACCEPT_STRING_AS_BOOLEAN #2114

eximius313 opened this issue Aug 17, 2018 · 4 comments

Comments

@eximius313
Copy link

eximius313 commented Aug 17, 2018

  • Check to see if this issue has already been reported (quick glance at existing issues)
  • Include version information for Jackson version you use: jackson-databind-2.9.5

Currently Jackson deserializes {"myValue" : "true"} as Boolean which is not always desirable (because sometimes strict types are required: {"myValue" : true}).

Could you please introduce DeserializationFeature.ACCEPT_STRING_AS_BOOLEAN (simmilar to DeserializationFeature.ACCEPT_FLOAT_AS_INT), which will be enabled by default to cover backward compatibility, but can be disabled if not wanted.

Thank you in advance

@cowtowncoder
Copy link
Member

Thank you for your suggestion. The basic idea of allowing stricter handling makes sense.

However: there is already MapperFeature.ALLOW_COERCION_OF_SCALARS which I think should apply here. You can try to see if disabling it works for booleans: if not, it's a bug.
Looking at tests I think it should work (2.9.6), but let me know if you find otherwise.

Going forward I also hope to support existing property @JsonFormat(lenient = OptBoolean.FALSE) for wider range of types. As is, it is only supported by date/time types (JDK ones), but it seems to me it should work for primitives/wrappers at least as well.

@eximius313
Copy link
Author

you are right MapperFeature.ALLOW_COERCION_OF_SCALARS indeed works.
Shall I close this issue or let it open for @JsonFormat(lenient = OptBoolean.FALSE)?

@cowtowncoder
Copy link
Member

@eximius313 Thank you for verifying it works. I can close this issue and ensure there is a follow-up for lenient option.

@cowtowncoder
Copy link
Member

I think #2113 should cover boolean too (will verify).

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