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

ALLOW_COERCION_OF_SCALARS ignored deserializing scalars with Afterburner #69

Closed
dansanduleac opened this issue Jan 9, 2019 · 0 comments
Milestone

Comments

@dansanduleac
Copy link
Contributor

dansanduleac commented Jan 9, 2019

Let's look at deserializing an integer field, for example.

The code path in afterburner ends up here:

int v = p.hasToken(JsonToken.VALUE_NUMBER_INT) ? p.getIntValue() : _deserializeInt(p, ctxt);

If the value being deserialized is not a VALUE_NUMBER_INT, then the code delegates to _deserializeInt which will always attempt to coerce a VALUE_STRING to an integer:

if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return 0;
}
try {
int len = text.length();
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw ctxt.weirdStringException(text, Integer.TYPE,
"Overflow: numeric value ("+text+") out of range of int ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
}
return (int) l;
}
if (len == 0) {
return 0;
}
return NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, Integer.TYPE, "not a valid int value");
}
}

This code path should only be enabled if MapperFeature.ALLOW_COERCION_OF_SCALARS is enabled.

Similarly, this check should be performed when attempting to deserialize other scalar types like boolean and long.

@dansanduleac dansanduleac changed the title ALLOW_COERCION_OF_SCALARS ignored deserializing int with afterburner ALLOW_COERCION_OF_SCALARS ignored deserializing scalars with afterburner Jan 9, 2019
@cowtowncoder cowtowncoder added this to the 2.9.9 milestone Jan 28, 2019
@cowtowncoder cowtowncoder changed the title ALLOW_COERCION_OF_SCALARS ignored deserializing scalars with afterburner ALLOW_COERCION_OF_SCALARS ignored deserializing scalars with Afterburner Jan 28, 2019
cowtowncoder added a commit that referenced this issue Jan 28, 2019
stevenschlansker pushed a commit to stevenschlansker/jackson-modules-base that referenced this issue Sep 5, 2019
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