private static byte getTTypeFromJavaType(Type jType) {

    // check primitive types and final classes
    if (jType == Boolean.TYPE || jType == Boolean.class)   return TType.BOOL;
    if (jType == Byte.TYPE    || jType == Byte.class)      return TType.BYTE;
    if (jType == Short.TYPE   || jType == Short.class)     return TType.I16;
    if (jType == Integer.TYPE || jType == Integer.class)   return TType.I32;
    if (jType == Long.TYPE    || jType == Long.class)      return TType.I64;
    if (jType == Double.TYPE  || jType == Double.class)    return TType.DOUBLE;
    if (jType == String.class)                             return TType.STRING;
    if (jType == byte[].class)                             return TType.STRING; // buffer
    if (jType == Void.class)                               return TType.VOID;

    // non-generic simple classes
    if (jType instanceof Class) {
      Class<?> klass = (Class<?>) jType;

      if (TEnum.class.isAssignableFrom(klass))      return TType.ENUM;
      if (ByteBuffer.class.isAssignableFrom(klass)) return TType.STRING; // buffer (ByteBuffer)
      if (TBase.class.isAssignableFrom(klass))      return TType.STRUCT;
    }

    // generic types
    if (jType instanceof ParameterizedType) {
      Class<?> klass = (Class<?>) ((ParameterizedType)jType).getRawType();

      if (Map.class.isAssignableFrom(klass))    return TType.MAP;
      if (Set.class.isAssignableFrom(klass))    return TType.SET;
      if (List.class.isAssignableFrom(klass))   return TType.LIST;
    }

    throw new IllegalArgumentException("cannot convert java type '" + jType + "'  to thrift type");
  }
private static byte getTTypeFromJavaType(Type jType) {

    
    if (jType == Boolean.TYPE || jType == Boolean.class)   return TType.BOOL;
    if (jType == Byte.TYPE    || jType == Byte.class)      return TType.BYTE;
    if (jType == Short.TYPE   || jType == Short.class)     return TType.I16;
    if (jType == Integer.TYPE || jType == Integer.class)   return TType.I32;
    if (jType == Long.TYPE    || jType == Long.class)      return TType.I64;
    if (jType == Double.TYPE  || jType == Double.class)    return TType.DOUBLE;
    if (jType == String.class)                             return TType.STRING;
    if (jType == byte[].class)                             return TType.STRING; 
    if (jType == Void.class)                               return TType.VOID;

    
    if (jType instanceof Class) {
      Class<?> klass = (Class<?>) jType;

      if (TEnum.class.isAssignableFrom(klass))      return TType.ENUM;
      if (ByteBuffer.class.isAssignableFrom(klass)) return TType.STRING; 
      if (TBase.class.isAssignableFrom(klass))      return TType.STRUCT;
    }

    
    if (jType instanceof ParameterizedType) {
      Class<?> klass = (Class<?>) ((ParameterizedType)jType).getRawType();

      if (Map.class.isAssignableFrom(klass))    return TType.MAP;
      if (Set.class.isAssignableFrom(klass))    return TType.SET;
      if (List.class.isAssignableFrom(klass))   return TType.LIST;
    }

    throw new IllegalArgumentException("cannot convert java type '" + jType + "'  to thrift type");
  }
private static byte getTTypeFromJavaType ( Type jType ) { // check primitive types and final classes if ( jType == Boolean . TYPE || jType == Boolean . class ) return TType . BOOL ; if ( jType == Byte . TYPE || jType == Byte . class ) return TType . BYTE ; if ( jType == Short . TYPE || jType == Short . class ) return TType . I16 ; if ( jType == Integer . TYPE || jType == Integer . class ) return TType . I32 ; if ( jType == Long . TYPE || jType == Long . class ) return TType . I64 ; if ( jType == Double . TYPE || jType == Double . class ) return TType . DOUBLE ; if ( jType == String . class ) return TType . STRING ; if ( jType == byte [ ] . class ) return TType . STRING ; // buffer if ( jType == Void . class ) return TType . VOID ; // non-generic simple classes if ( jType instanceof Class ) { Class < ? > klass = ( Class < ? > ) jType ; if ( TEnum . class . isAssignableFrom ( klass ) ) return TType . ENUM ; if ( ByteBuffer . class . isAssignableFrom ( klass ) ) return TType . STRING ; // buffer (ByteBuffer) if ( TBase . class . isAssignableFrom ( klass ) ) return TType . STRUCT ; } // generic types if ( jType instanceof ParameterizedType ) { Class < ? > klass = ( Class < ? > ) ( ( ParameterizedType ) jType ) . getRawType ( ) ; if ( Map . class . isAssignableFrom ( klass ) ) return TType . MAP ; if ( Set . class . isAssignableFrom ( klass ) ) return TType . SET ; if ( List . class . isAssignableFrom ( klass ) ) return TType . LIST ; } throw new IllegalArgumentException ( "cannot convert java type '" + jType + "'  to thrift type" ) ; }
Derives Thrift TType from java {@link Type} of a thrift field
Derives Thrift TType from java {