Utils { public static Class<?> getGenericTypeNameFromTypeConverter(TypeConverter<?, ?> typeConverter, int genericTypeIndex) throws Exception { Class<? extends TypeConverter> typeConverterClass = typeConverter.getClass(); Type[] genericInterfaces = typeConverterClass.getGenericInterfaces(); Type genericInterface = genericInterfaces[0]; if (!(genericInterface instanceof ParameterizedType)) { throw new Exception("The type converter" + typeConverterClass.getName() + " should be a parametrized type"); } ParameterizedType parameterizedType = (ParameterizedType) genericInterface; Type type = parameterizedType.getActualTypeArguments()[genericTypeIndex]; String className = getClassName(type); return Class.forName(className); } private  Utils(); static void checkNotNull(Object argument, String argumentName); static void checkArgument(boolean assertion, String message); static Map<String, Method> getGetters(final Class<?> type); static String formatTime(LocalDateTime time); static String formatDuration(Duration duration); static String formatErrorThreshold(final long errorThreshold); static List<P> extractPayloads(final List<? extends Record<P>> records); static Class<?> getGenericTypeNameFromTypeConverter(TypeConverter<?, ?> typeConverter, int genericTypeIndex); static final String LINE_SEPARATOR; static final String FILE_SEPARATOR; static final String JAVA_IO_TMPDIR; static final String NOT_APPLICABLE; }
@Test public void testGettingGenericTypeFromTypeConverter() throws Exception { TypeConverter<LocalDate, String> typeConverter = new TypeConverter<LocalDate, String>() { @Override public String convert(LocalDate value) { return DateTimeFormatter.ISO_LOCAL_DATE.format(value); } }; Class<?> firstGenericType = Utils.getGenericTypeNameFromTypeConverter(typeConverter, 0); Class<?> secondGenericType = Utils.getGenericTypeNameFromTypeConverter(typeConverter, 1); assertThat(firstGenericType).isEqualTo(LocalDate.class); assertThat(secondGenericType).isEqualTo(String.class); }