take numeric types into account for array defaults (#14694)

This commit is contained in:
Robbert van Waveren 2023-02-16 11:28:26 +01:00 committed by GitHub
parent 11d9d4346e
commit ae0ed022d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1013,6 +1013,20 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
} else { } else {
if (cp.items.isString) { // array item is string if (cp.items.isString) { // array item is string
defaultValue = String.format(Locale.ROOT, "\"%s\"", StringUtils.join(_values, "\", \"")); 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 } else { // array item is non-string, e.g. integer
defaultValue = StringUtils.join(_values, ", "); defaultValue = StringUtils.join(_values, ", ");
} }