@SuppressWarnings({ "unchecked", "rawtypes" })
	public static final <TO, FROM> TO convert(Class<TO> to, FROM from) {

		// Convert null value
		if (from == null || to == null) {
			return null;
		}

		// Convert "null" String to null
		if ("null".equals(from)) {
			return null;
		}

		// Class is same
		if (to == Object.class || from.getClass() == to) {
			return (TO) from;
		}

		// BSON conversion
		boolean isFromMap = from != null && from instanceof Map;
		if (isFromMap) {
			Object subValue = getSubValue((Map) from);
			if (subValue != null) {
				return convert(to, subValue);
			}
		}

		// Convert FROM -> TO
		DataConverterKey<TO, FROM> key = new DataConverterKey<TO, FROM>(to, (Class<FROM>) from.getClass());
		DataConverter<TO, FROM> converter = (DataConverter<TO, FROM>) converters.get(key);
		if (converter != null) {
			return converter.convert(from);
		}

		// Convert any -> TO
		converter = (DataConverter<TO, FROM>) defaultConverters.get(to);
		if (converter != null) {
			return converter.convert(from);
		}

		// Converter not found
		throw new IllegalArgumentException("Unable to convert " + from.getClass() + " to " + to
				+ ", converter not found in DataConverterRegistry!");
	}
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public static final < TO , FROM > TO convert ( Class < TO > to , FROM from ) { if ( from == null || to == null ) { return null ; } if ( "null" . equals ( from ) ) { return null ; } if ( to == Object . class || from . getClass ( ) == to ) { return ( TO ) from ; } boolean isFromMap = from != null && from instanceof Map ; if ( isFromMap ) { Object subValue = getSubValue ( ( Map ) from ) ; if ( subValue != null ) { return convert ( to , subValue ) ; } } DataConverterKey < TO , FROM > key = new DataConverterKey < TO , FROM > ( to , ( Class < FROM > ) from . getClass ( ) ) ; DataConverter < TO , FROM > converter = ( DataConverter < TO , FROM > ) converters . get ( key ) ; if ( converter != null ) { return converter . convert ( from ) ; } converter = ( DataConverter < TO , FROM > ) defaultConverters . get ( to ) ; if ( converter != null ) { return converter . convert ( from ) ; } throw new IllegalArgumentException ( "Unable to convert " + from . getClass ( ) + " to " + to + ", converter not found in DataConverterRegistry!" ) ; }
Converts "FROM" object to "TO" format / class.

@param <TO>
target class to convert the source object
@param <FROM>
source class
@param to
target type
@param from
source object

@return converted value in "TO" format / class