public Object toObject(String string, Class<?> targetClass) { if (!StringUtils.hasText(string)) { return null; } DateFormat dateFormat = getDateFormat(); try { return dateFormat.parse(string); } catch (ParseException e) { throw new InvalidFormatException(string, getPattern(dateFormat), e); } }
public Object toObject(String string, Class<?> targetClass) { if (!StringUtils.hasText(string)) { return null; } DateFormat dateFormat = getDateFormat(); try { return dateFormat.parse(string); } catch (ParseException e) { throw new InvalidFormatException(string, getPattern(dateFormat), e); } }
public Object toObject(String string, Class targetClass) throws Exception { if (!StringUtils.hasText(string)) { return null; } DateFormat dateFormat = getDateFormat(); try { return dateFormat.parse(string); } catch (ParseException e) { throw new InvalidFormatException(string, getPattern(dateFormat), e); } }
@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); }
@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); }