@SuppressWarnings("unchecked") protected Object toObject(String string, Class<?> targetClass) { ParsePosition parsePosition = new ParsePosition(0); NumberFormat format = numberFormatFactory.getNumberFormat(); Number number = format.parse(string, parsePosition); if (number == null) { // no object could be parsed throw new InvalidFormatException(string, getPattern(format)); } if (!lenient) { if (string.length() != parsePosition.getIndex()) { // indicates a part of the string that was not parsed; e.g. ".5" in 1234.5 when parsing an Integer throw new InvalidFormatException(string, getPattern(format)); } } return convertToNumberClass(number, (Class<? extends Number>) targetClass); }
@SuppressWarnings("unchecked") protected Object toObject(String string, Class<?> targetClass) { ParsePosition parsePosition = new ParsePosition(0); NumberFormat format = numberFormatFactory.getNumberFormat(); Number number = format.parse(string, parsePosition); if (number == null) { // no object could be parsed throw new InvalidFormatException(string, getPattern(format)); } if (!lenient) { if (string.length() != parsePosition.getIndex()) { // indicates a part of the string that was not parsed; e.g. ".5" in 1234.5 when parsing an Integer throw new InvalidFormatException(string, getPattern(format)); } } return convertToNumberClass(number, (Class<? extends Number>) targetClass); }
protected Object toObject(String string, Class targetClass) throws Exception { ParsePosition parsePosition = new ParsePosition(0); NumberFormat format = numberFormatFactory.getNumberFormat(); Number number = format.parse(string, parsePosition); if (number == null) { // no object could be parsed throw new InvalidFormatException(string, getPattern(format)); } if (!lenient) { if (string.length() != parsePosition.getIndex()) { // indicates a part of the string that was not parsed; e.g. ".5" in 1234.5 when parsing an Integer throw new InvalidFormatException(string, getPattern(format)); } } return convertToNumberClass(number, targetClass); }