Skip to content

Commit

Permalink
Fix integer json parsing probe definition
Browse files Browse the repository at this point in the history
Following #7676 issue, numbers parsed from the json probe definition
are still considered as long value which still makes then unfittable
to be used as key for Integer -> Integer map.
Now we parse integers (without dot numbers) as long and see if they
fit into an integer, then downgrade them as DSL value with integer
type.
  • Loading branch information
jpbempel committed Nov 14, 2024
1 parent ea008a2 commit fd1bd00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ public static ValueExpression<?> asValueExpression(JsonReader reader) throws IOE
if (numberStrValue.indexOf('.') > 0) {
return DSL.value(Double.parseDouble(numberStrValue));
}
return DSL.value(Long.parseLong(numberStrValue));
long longValue = Long.parseLong(numberStrValue);
// checks if the parsed number fits into integer range
if (longValue <= Integer.MAX_VALUE && longValue >= Integer.MIN_VALUE) {
return DSL.value((int) longValue);
}
return DSL.value(longValue);
}
case STRING:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ public void topLevelPrimitives() {
"el",
Values.NULL_OBJECT,
Boolean.TRUE,
Boolean.FALSE
Boolean.FALSE,
42,
Integer.MAX_VALUE,
-42,
Integer.MIN_VALUE,
17315993717L,
-17315993717L,
3.14
};
List<String> lines = loadLinesFromResource("/test_one_liner_value_expr_02.txt");
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@
{"dsl": "", "json": null}
{"dsl": "", "json": true}
{"dsl": "", "json": false}
{"dsl": "", "json": 42}
{"dsl": "", "json": 2147483647}
{"dsl": "", "json": -42}
{"dsl": "", "json": -2147483648}
{"dsl": "", "json": 17315993717}
{"dsl": "", "json": -17315993717}
{"dsl": "", "json": 3.14}

0 comments on commit fd1bd00

Please sign in to comment.