You could put the @SuppressWarnings("unchecked") on this method, make it not static, and change its return type to ThriftStructCodec<T>