@ Unstable public static String serializeType ( Type type ) { if ( type == null ) { return null ; } StringBuilder sb = new StringBuilder ( ) ; if ( type instanceof ParameterizedType ) { ParameterizedType parameterizedType = ( ParameterizedType ) type ; String rawTypeName = getTypeName ( parameterizedType . getRawType ( ) ) ; if ( parameterizedType . getOwnerType ( ) != null ) { if ( parameterizedType . getOwnerType ( ) instanceof Class ) { sb . append ( ( ( Class < ? > ) parameterizedType . getOwnerType ( ) ) . getName ( ) ) ; } else { sb . append ( parameterizedType . getOwnerType ( ) . toString ( ) ) ; } sb . append ( ' ' ) ; if ( parameterizedType . getOwnerType ( ) instanceof ParameterizedType ) { // Find simple name of nested type by removing the // shared prefix with owner. sb . append ( rawTypeName . replace ( ( ( Class < ? > ) ( ( ParameterizedType ) parameterizedType . getOwnerType ( ) ) . getRawType ( ) ) . getName ( ) + ' ' , "" ) ) ; } else { sb . append ( rawTypeName ) ; } } else { sb . append ( rawTypeName ) ; } if ( parameterizedType . getActualTypeArguments ( ) != null && parameterizedType . getActualTypeArguments ( ) . length > 0 ) { sb . append ( OPEN_GENERIC ) ; boolean first = true ; for ( Type typeArgument : parameterizedType . getActualTypeArguments ( ) ) { if ( ! first ) { sb . append ( ", " ) ; } sb . append ( getTypeName ( typeArgument ) ) ; first = false ; } sb . append ( CLOSE_GENERIC ) ; } } else { sb . append ( getTypeName ( type ) ) ; } return sb . toString ( ) ; }
Serialize a type in a String using a standard definition .