public Object convertValue()

in core/src/main/java/org/apache/struts2/conversion/impl/NumberConverter.java [38:88]


    public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) {
        if (value instanceof String) {
            String stringValue = String.valueOf(value);

            if (toType == BigDecimal.class) {
                return convertToBigDecimal(context, stringValue);
            } else if (toType == BigInteger.class) {
                return new BigInteger(stringValue);
            } else if (toType == Double.class || toType == double.class) {
                return convertToDouble(context, stringValue);
            } else if (toType == Float.class || toType == float.class) {
                return convertToFloat(context, stringValue);
            } else if (toType.isPrimitive()) {
                Object convertedValue = super.convertValue(context, value, toType);

                if (!isInRange((Number) convertedValue, stringValue, toType))
                    throw new TypeConversionException("Overflow or underflow casting: \"" + stringValue + "\" into class " + convertedValue.getClass().getName());

                return convertedValue;
            } else {
                if (stringValue.isEmpty()) {
                    return null;
                }
                NumberFormat numFormat = NumberFormat.getInstance(getLocale(context));
                ParsePosition parsePos = new ParsePosition(0);
                if (isIntegerType(toType)) {
                    numFormat.setParseIntegerOnly(true);
                }
                numFormat.setGroupingUsed(true);
                Number number = numFormat.parse(stringValue, parsePos);

                if (parsePos.getIndex() != stringValue.length()) {
                    throw new TypeConversionException("Unparseable number: \"" + stringValue + "\" at position "
                        + parsePos.getIndex());
                } else {
                    if (!isInRange(number, stringValue, toType))
                        throw new TypeConversionException("Overflow or underflow casting: \"" + stringValue + "\" into class " + number.getClass().getName());

                    value = super.convertValue(context, number, toType);
                }
            }
        } else if (value instanceof Object[] objArray) {

            if (objArray.length == 1) {
                return convertValue(context, null, null, null, objArray[0], toType);
            }
        }

        // pass it through DefaultTypeConverter
        return super.convertValue(context, value, toType);
    }