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

Case-insensitive boolean deserialization #2132

Closed
wants to merge 1 commit into from
Closed

Case-insensitive boolean deserialization #2132

wants to merge 1 commit into from

Conversation

remal
Copy link
Contributor

@remal remal commented Sep 7, 2018

It's a fix for #1852

@cowtowncoder
Copy link
Member

First of all, thank you for PR!

Now, as per my notes I think what is needed is support for using either "leniency" (via @JsonFormat.lenient), or case-sensitivity. Actually probably latter.
So I am not sure whether to apply this at this point.
Problem here is that there are users who want stricter handling (as well as others who want more flexible one, of course :) ), and I would like to have controls in place to allow both, before extending definition.

@remal
Copy link
Contributor Author

remal commented Sep 8, 2018

@cowtowncoder I believe I saw a special Jackson setting that switches from strict/not strict. Let me do a little research on Monday...

@remal
Copy link
Contributor Author

remal commented Sep 14, 2018

@cowtowncoder I thought about com.fasterxml.jackson.databind.MapperFeature.ALLOW_COERCION_OF_SCALARS. But this option is not applicable here. We can create another option, but do Jackson really need it?

@cowtowncoder
Copy link
Member

So: since 2.10 adds more specific JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_VALUES / MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES, I think that is what needs to be used here.
Will close this PR.

@ghanekaromkar
Copy link

ghanekaromkar commented Nov 22, 2019

I tried using the new Features in my code but it does not help me against uppercased value like "TRUE"
My code
mapper.configure(MapperFeature.USE_STD_BEAN_NAMING, true) .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES, true) .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true) .configure(SerializationFeature.FAIL_ON_SELF_REFERENCES, true) .setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

Maybe because BooleanDeserializer does not consider the Feature value but I could be wrong

if (t == JsonToken.VALUE_STRING) {
String text = p.getText().trim();
// [databind#422]: Allow aliases
if ("true".equals(text) || "True".equals(text)) {
_verifyStringForScalarCoercion(ctxt, text);
return Boolean.TRUE;
}
if ("false".equals(text) || "False".equals(text)) {
_verifyStringForScalarCoercion(ctxt, text);
return Boolean.FALSE;
}
if (text.length() == 0) {
return (Boolean) _coerceEmptyString(ctxt, _primitive);
}
if (_hasTextualNull(text)) {
return (Boolean) _coerceTextualNull(ctxt, _primitive);
}
return (Boolean) ctxt.handleWeirdStringValue(_valueClass, text,
"only \"true\" or \"false\" recognized");
}

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