Skip to content

Commit

Permalink
take numeric types into account for array defaults (#14694)
Browse files Browse the repository at this point in the history
  • Loading branch information
robbertvanwaveren authored Feb 16, 2023
1 parent 11d9d43 commit ae0ed02
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,20 @@ public String toArrayDefaultValue(CodegenProperty cp, Schema schema) {
} else {
if (cp.items.isString) { // array item is string
defaultValue = String.format(Locale.ROOT, "\"%s\"", StringUtils.join(_values, "\", \""));
} else if (cp.items.isNumeric) {
defaultValue = _values.stream()
.map(v -> {
if ("BigInteger".equals(cp.items.dataType)) {
return "new BigInteger(\"" + v + "\")";
} else if ("BigDecimal".equals(cp.items.dataType)) {
return "new BigDecimal(\"" + v + "\")";
} else if (cp.items.isFloat) {
return v + "f";
} else {
return v;
}
})
.collect(Collectors.joining(", "));
} else { // array item is non-string, e.g. integer
defaultValue = StringUtils.join(_values, ", ");
}
Expand Down

0 comments on commit ae0ed02

Please sign in to comment.