@Test void convertColor() { assertEquals(Color.WHITE, this.converterManager.convert(Color.class, "#ffffff")); }
@Override public <T> T convert(Type targetType, Object value) { if (targetType instanceof Class && ((Class<?>) targetType).isInstance(value)) { return (T) value; } if (targetType instanceof WildcardType) { Type[] upperBounds = ((WildcardType) targetType).getUpperBounds(); if (upperBounds.length == 0) { return (T) value; } else { return convert(upperBounds[0], value); } } Type converterType = targetType; if (converterType == String.class && value != null) { converterType = value.getClass(); } Converter<T> converter = lookupConverter(converterType); if (converter != null) { return converter.convert(targetType, value); } else { throw new ConversionException( "Cannot find Converter to convert value [" + value + "] to type [" + targetType + "] "); } }
DefaultConverterManager implements ConverterManager { @Override public <T> T convert(Type targetType, Object value) { if (targetType instanceof Class && ((Class<?>) targetType).isInstance(value)) { return (T) value; } if (targetType instanceof WildcardType) { Type[] upperBounds = ((WildcardType) targetType).getUpperBounds(); if (upperBounds.length == 0) { return (T) value; } else { return convert(upperBounds[0], value); } } Type converterType = targetType; if (converterType == String.class && value != null) { converterType = value.getClass(); } Converter<T> converter = lookupConverter(converterType); if (converter != null) { return converter.convert(targetType, value); } else { throw new ConversionException( "Cannot find Converter to convert value [" + value + "] to type [" + targetType + "] "); } } }
DefaultConverterManager implements ConverterManager { @Override public <T> T convert(Type targetType, Object value) { if (targetType instanceof Class && ((Class<?>) targetType).isInstance(value)) { return (T) value; } if (targetType instanceof WildcardType) { Type[] upperBounds = ((WildcardType) targetType).getUpperBounds(); if (upperBounds.length == 0) { return (T) value; } else { return convert(upperBounds[0], value); } } Type converterType = targetType; if (converterType == String.class && value != null) { converterType = value.getClass(); } Converter<T> converter = lookupConverter(converterType); if (converter != null) { return converter.convert(targetType, value); } else { throw new ConversionException( "Cannot find Converter to convert value [" + value + "] to type [" + targetType + "] "); } }  }
DefaultConverterManager implements ConverterManager { @Override public <T> T convert(Type targetType, Object value) { if (targetType instanceof Class && ((Class<?>) targetType).isInstance(value)) { return (T) value; } if (targetType instanceof WildcardType) { Type[] upperBounds = ((WildcardType) targetType).getUpperBounds(); if (upperBounds.length == 0) { return (T) value; } else { return convert(upperBounds[0], value); } } Type converterType = targetType; if (converterType == String.class && value != null) { converterType = value.getClass(); } Converter<T> converter = lookupConverter(converterType); if (converter != null) { return converter.convert(targetType, value); } else { throw new ConversionException( "Cannot find Converter to convert value [" + value + "] to type [" + targetType + "] "); } }  @Override T convert(Type targetType, Object value); @Override Converter<T> getConverter(Type targetType); }
DefaultConverterManager implements ConverterManager { @Override public <T> T convert(Type targetType, Object value) { if (targetType instanceof Class && ((Class<?>) targetType).isInstance(value)) { return (T) value; } if (targetType instanceof WildcardType) { Type[] upperBounds = ((WildcardType) targetType).getUpperBounds(); if (upperBounds.length == 0) { return (T) value; } else { return convert(upperBounds[0], value); } } Type converterType = targetType; if (converterType == String.class && value != null) { converterType = value.getClass(); } Converter<T> converter = lookupConverter(converterType); if (converter != null) { return converter.convert(targetType, value); } else { throw new ConversionException( "Cannot find Converter to convert value [" + value + "] to type [" + targetType + "] "); } }  @Override T convert(Type targetType, Object value); @Override Converter<T> getConverter(Type targetType);  }