public final Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception { if (target != null) { return toString(target); } else { return ""; } }
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception { return converter.convertTargetToSourceClass(source, targetClass); }
public Class<?> getSourceClass() { return converter.getTargetClass(); }
/** * Add all default converters to the conversion service. */ protected void addDefaultConverters() { addConverter(new StringToByte()); addConverter(new StringToBoolean()); addConverter(new StringToCharacter()); addConverter(new StringToShort()); addConverter(new StringToInteger()); addConverter(new StringToLong()); addConverter(new StringToFloat()); addConverter(new StringToDouble()); addConverter(new StringToBigInteger()); addConverter(new StringToBigDecimal()); addConverter(new StringToLocale()); addConverter(new StringToDate()); addConverter(new StringToLabeledEnum()); addConverter(new ObjectToCollection(this)); addConverter(new NumberToNumber()); if (ClassUtils.isPresent("java.lang.Enum", this.getClass().getClassLoader())) { addConverter(new StringToEnum()); } }
StringToDate std = new StringToDate(); std.setPattern("dd.MM.yyyy");
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 Class<?> getTargetClass() { return converter.getSourceClass(); }
public String toString(Object target) throws Exception { Date date = (Date) target; if (date == null) { return ""; } return getDateFormat().format(date); }
public final Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception { String string = (String) source; if (string != null && string.length() > 0) { return toObject(string, targetClass); } else { return null; } }
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 final Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception { if (target != null) { return toString(target); } else { return ""; } }
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception { return converter.convertTargetToSourceClass(source, targetClass); }
public Class getSourceClass() { return converter.getTargetClass(); }
public Class<?> getTargetClass() { return converter.getSourceClass(); }
public String toString(Object target) { Date date = (Date) target; if (date == null) { return ""; } return getDateFormat().format(date); }
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); } }
public final Object convertTargetToSourceClass(Object target, Class sourceClass) throws Exception { if (target != null) { return toString(target); } else { return ""; } }
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception { return converter.convertTargetToSourceClass(source, targetClass); }
public Class<?> getSourceClass() { return converter.getTargetClass(); }
public Class getTargetClass() { return converter.getSourceClass(); }