@Test void convertUnsupportedType() { Throwable exception = assertThrows(ConversionException.class, () -> this.converterManager.convert(DefaultConverterManagerTest.class, "#ffffff")); assertEquals("Failed to find a Converter to convert from [java.lang.String] to " + "[org.xwiki.properties.internal.DefaultConverterManagerTest]", exception.getMessage()); }
@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);  }