/** * Look up and return any registered {@link Converter} for the specified * source and destination class; if there is no registered Converter, * return <code>null</code>. * * @param sourceType Class of the value being converted * @param targetType Class of the value to be converted to * @return The registered {@link Converter} or <code>null</code> if not found */ public static Converter lookup(final Class<?> sourceType, final Class<?> targetType) { return ConvertUtilsBean.getInstance().lookup(sourceType, targetType); }
return lookup(targetType); converter = lookup(sourceType); if (converter == null && (sourceType.isArray() || Collection.class.isAssignableFrom(sourceType))) { converter = lookup(String[].class); converter = lookup(String.class); converter = lookup(sourceType); converter = lookup(String[].class); return lookup(targetType);
/** * Look up and return any registered {@link Converter} for the specified * source and destination class; if there is no registered Converter, * return <code>null</code>. * * @param sourceType Class of the value being converted * @param targetType Class of the value to be converted to * @return The registered {@link Converter} or <code>null</code> if not found */ public static Converter lookup(final Class<?> sourceType, final Class<?> targetType) { return ConvertUtilsBean.getInstance().lookup(sourceType, targetType); }
return lookup(targetType); converter = lookup(sourceType); if (converter == null && (sourceType.isArray() || Collection.class.isAssignableFrom(sourceType))) { converter = lookup(String[].class); converter = lookup(String.class); converter = lookup(sourceType); converter = lookup(String[].class); return lookup(targetType);
/** * <p>Look up and return any registered {@link Converter} for the specified * destination class; if there is no registered Converter, return * <code>null</code>.</p> * * <p>For more details see <code>ConvertUtilsBean</code>.</p> * * @param clazz Class for which to return a registered Converter * @return The registered {@link Converter} or <code>null</code> if not found * @see ConvertUtilsBean#lookup(Class) */ public static Converter lookup(final Class<?> clazz) { return ConvertUtilsBean.getInstance().lookup(clazz); }
/** * <p>Look up and return any registered {@link Converter} for the specified * destination class; if there is no registered Converter, return * <code>null</code>.</p> * * <p>For more details see <code>ConvertUtilsBean</code>.</p> * * @param clazz Class for which to return a registered Converter * @return The registered {@link Converter} or <code>null</code> if not found * @see ConvertUtilsBean#lookup(Class) */ public static Converter lookup(final Class<?> clazz) { return ConvertUtilsBean.getInstance().lookup(clazz); }
/** * Convert the specified value to an object of the specified class (if * possible). Otherwise, return a String representation of the value. * * @param value Value to be converted (may be null) * @param clazz Java class to be converted to (must not be null) * @return The converted value * * @throws ConversionException if thrown by an underlying Converter */ public Object convert(final String value, final Class<?> clazz) { if (log.isDebugEnabled()) { log.debug("Convert string '" + value + "' to class '" + clazz.getName() + "'"); } Converter converter = lookup(clazz); if (converter == null) { converter = lookup(String.class); } if (log.isTraceEnabled()) { log.trace(" Using converter " + converter); } return (converter.convert(clazz, value)); }
/** * Convert the specified value to an object of the specified class (if * possible). Otherwise, return a String representation of the value. * * @param value Value to be converted (may be null) * @param clazz Java class to be converted to (must not be null) * @return The converted value * * @throws ConversionException if thrown by an underlying Converter */ public Object convert(final String value, final Class<?> clazz) { if (log.isDebugEnabled()) { log.debug("Convert string '" + value + "' to class '" + clazz.getName() + "'"); } Converter converter = lookup(clazz); if (converter == null) { converter = lookup(String.class); } if (log.isTraceEnabled()) { log.trace(" Using converter " + converter); } return (converter.convert(clazz, value)); }
/** * Convert the specified value into a String. If the specified value * is an array, the first element (converted to a String) will be * returned. The registered {@link Converter} for the * <code>java.lang.String</code> class will be used, which allows * applications to customize Object->String conversions (the default * implementation simply uses toString()). * * @param value Value to be converted (may be null) * @return The converted String value or null if value is null */ public String convert(Object value) { if (value == null) { return null; } else if (value.getClass().isArray()) { if (Array.getLength(value) < 1) { return (null); } value = Array.get(value, 0); if (value == null) { return null; } else { final Converter converter = lookup(String.class); return (converter.convert(String.class, value)); } } else { final Converter converter = lookup(String.class); return (converter.convert(String.class, value)); } }
/** * Convert the specified value into a String. If the specified value * is an array, the first element (converted to a String) will be * returned. The registered {@link Converter} for the * <code>java.lang.String</code> class will be used, which allows * applications to customize Object->String conversions (the default * implementation simply uses toString()). * * @param value Value to be converted (may be null) * @return The converted String value or null if value is null */ public String convert(Object value) { if (value == null) { return null; } else if (value.getClass().isArray()) { if (Array.getLength(value) < 1) { return (null); } value = Array.get(value, 0); if (value == null) { return null; } else { final Converter converter = lookup(String.class); return (converter.convert(String.class, value)); } } else { final Converter converter = lookup(String.class); return (converter.convert(String.class, value)); } }
/** * <p>Convert the value to an object of the specified class (if * possible).</p> * * @param value Value to be converted (may be null) * @param type Class of the value to be converted to * @return The converted value * * @throws ConversionException if thrown by an underlying Converter * @since 1.8.0 */ protected Object convert(final Object value, final Class<?> type) { final Converter converter = getConvertUtils().lookup(type); if (converter != null) { log.trace(" USING CONVERTER " + converter); return converter.convert(type, value); } else { return value; } }
/** * <p>Convert the value to an object of the specified class (if * possible).</p> * * @param value Value to be converted (may be null) * @param type Class of the value to be converted to * @return The converted value * * @throws ConversionException if thrown by an underlying Converter * @since 1.8.0 */ protected Object convert(final Object value, final Class<?> type) { final Converter converter = getConvertUtils().lookup(type); if (converter != null) { log.trace(" USING CONVERTER " + converter); return converter.convert(type, value); } else { return value; } }
.getInstance() .getConvertUtils() .lookup(targetClass); if (null != converter) { return converter.convert(targetClass, source);
@Override public Converter lookup(Class clazz) { final Converter converter = super.lookup(clazz); // no specific converter for this class, so it's neither a String, (which has a default converter), // nor any known object that has a custom converter for it. It might be an enum ! // We can't just register the converter - because they're registered on a per class basis. if (converter == null && clazz.isEnum()) { return enumConverter; } return converter; }
@Override public Converter lookup(Class clazz) { final Converter converter = super.lookup(clazz); // no specific converter for this class, so it's neither a String, (which has a default converter), // nor any known object that has a custom converter for it. It might be an enum ! if (converter == null && clazz.isEnum()) { return enumConverter; } return converter; }
@Override public Converter lookup(Class<?> sourceType, Class<?> targetType) { Pair<Class<?>, Class<?>> key = Pair.of(sourceType, targetType); if (bidirectionalConverters.containsKey(key)) { return bidirectionalConverters.get(key); } return super.lookup(sourceType, targetType); } }