jodd-bean/src/main/java/jodd/typeconverter/TypeConverterManager.java
@SuppressWarnings({"unchecked"})
	public <T> T convertType(final Object value, final Class<T> destinationType) {
		if (destinationType == Object.class) {
			// no conversion :)
			return (T) value;
		}

		final TypeConverter converter = lookup(destinationType);

		if (converter != null) {
			return (T) converter.convert(value);
		}

		// no converter

		if (value == null) {
			return null;
		}

		// check same instances
		if (ClassUtil.isInstanceOf(value, destinationType)) {
			return (T) value;
		}

		// handle destination arrays
		if (destinationType.isArray()) {
			ArrayConverter<T> arrayConverter = new ArrayConverter(this, destinationType.getComponentType());

			return (T) arrayConverter.convert(value);
		}

		// handle enums
		if (destinationType.isEnum()) {
			Object[] enums = destinationType.getEnumConstants();
			String valStr = value.toString();
			for (Object e : enums) {
				if (e.toString().equals(valStr)) {
					return (T) e;
				}
			}
		}

		// collection
		if (ClassUtil.isTypeOf(destinationType, Collection.class)) {
			// component type is unknown because of Java's type-erasure
			CollectionConverter<T> collectionConverter =
					new CollectionConverter(this, destinationType, Object.class);

			return (T) collectionConverter.convert(value);
		}

		// fail
		throw new TypeConversionException("Conversion failed of input type: " + value.getClass() + " into: " + destinationType.getName());
	}
@SuppressWarnings({"unchecked"})
	public <T> T convertType(final Object value, final Class<T> destinationType) {
		if (destinationType == Object.class) {
			// no conversion :)
			return (T) value;
		}

		final TypeConverter converter = lookup(destinationType);

		if (converter != null) {
			return (T) converter.convert(value);
		}

		// no converter

		if (value == null) {
			return null;
		}

		// check same instances
		if (ClassUtil.isInstanceOf(value, destinationType)) {
			return (T) value;
		}

		// handle destination arrays
		if (destinationType.isArray()) {
			ArrayConverter<T> arrayConverter = new ArrayConverter(this, destinationType.getComponentType());

			return (T) arrayConverter.convert(value);
		}

		// handle enums
		if (destinationType.isEnum()) {
			Object[] enums = destinationType.getEnumConstants();
			String valStr = value.toString();
			for (Object e : enums) {
				if (e.toString().equals(valStr)) {
					return (T) e;
				}
			}
		}

		// collection
		if (ClassUtil.isTypeOf(destinationType, Collection.class)) {
			// component type is unknown because of Java's type-erasure
			CollectionConverter<T> collectionConverter =
					new CollectionConverter(this, destinationType, Object.class);

			return (T) collectionConverter.convert(value);
		}

		// fail
		throw new TypeConversionException("Conversion failed of input type: " + value.getClass() + " into: " + destinationType.getName());
	}
@ SuppressWarnings ( { "unchecked" } ) public < T > T convertType ( final Object value , final Class < T > destinationType ) { if ( destinationType == Object . class ) { // no conversion :) return ( T ) value ; } final TypeConverter converter = lookup ( destinationType ) ; if ( converter != null ) { return ( T ) converter . convert ( value ) ; } // no converter if ( value == null ) { return null ; } // check same instances if ( ClassUtil . isInstanceOf ( value , destinationType ) ) { return ( T ) value ; } // handle destination arrays if ( destinationType . isArray ( ) ) { ArrayConverter < T > arrayConverter = new ArrayConverter ( this , destinationType . getComponentType ( ) ) ; return ( T ) arrayConverter . convert ( value ) ; } // handle enums if ( destinationType . isEnum ( ) ) { Object [ ] enums = destinationType . getEnumConstants ( ) ; String valStr = value . toString ( ) ; for ( Object e : enums ) { if ( e . toString ( ) . equals ( valStr ) ) { return ( T ) e ; } } } // collection if ( ClassUtil . isTypeOf ( destinationType , Collection . class ) ) { // component type is unknown because of Java's type-erasure CollectionConverter < T > collectionConverter = new CollectionConverter ( this , destinationType , Object . class ) ; return ( T ) collectionConverter . convert ( value ) ; } // fail throw new TypeConversionException ( "Conversion failed of input type: " + value . getClass ( ) + " into: " + destinationType . getName ( ) ) ; }
Converts an object to destination type. If type is registered, it's
{@link TypeConverter} will be used. If not, it scans of destination is
an array or enum, as those two cases are handled in a special way.
<p>
If destination type is one of common types, consider using {@link Converter}
instead for somewhat faster approach (no lookup).
Converts an object to destination type . If type is registered it s {