### Question:
TypeUtils { @SuppressWarnings("unchecked") public static <T> FromStringConverter<T> lookupFromStringConverter(TypeToken<T> type) { Class<? super T> rt = type.getRawType(); if (rt.equals(List.class)) { TypeToken elt = listElementType((TypeToken) type); FromStringConverter inner = lookupFromStringConverter(elt); return new ListParser(elt.getRawType(), inner); } else { return (FromStringConverter) StringConvert.INSTANCE.findConverter(rt); } } private  TypeUtils(); static Set<Class<?>> typeClosure(Class<?> type); static TypeToken<List<T>> makeListType(TypeToken<T> element); @SuppressWarnings("unchecked") static TypeToken<T> listElementType(TypeToken<? extends List<T>> token); static TypeToken<?> resolveTypeName(String type); @SuppressWarnings("unchecked") static String makeTypeName(TypeToken<T> type); @SuppressWarnings("unchecked") static FromStringConverter<T> lookupFromStringConverter(TypeToken<T> type);  }### Answer:
@Test public void testBasicFromString() { TypeToken<Integer> intType = TypeToken.of(Integer.class); FromStringConverter<Integer> cvt = TypeUtils.lookupFromStringConverter(intType); assertThat(cvt, notNullValue()); assertThat(cvt.convertFromString((Class) intType.getRawType(), "1348"), equalTo(1348)); }
@Test public void testStringListFromString() { TypeToken<List<String>> tok = new TypeToken<List<String>>() {}; FromStringConverter<List<String>> cvt = TypeUtils.lookupFromStringConverter(tok); assertThat(cvt, notNullValue()); List<String> result = cvt.convertFromString((Class) List.class, "foo,bar,\"hamster,salad\""); assertThat(result, contains("foo", "bar", "hamster,salad")); }
@Test public void testIntListFromString() { TypeToken<List<Integer>> tok = new TypeToken<List<Integer>>() {}; FromStringConverter<List<Integer>> cvt = TypeUtils.lookupFromStringConverter(tok); assertThat(cvt, notNullValue()); List<Integer> result = cvt.convertFromString((Class) List.class, "39,42"); assertThat(result, contains(39, 42)); }