DefaultTypeFinder implements TypeFinder { public Map<String, Class<?>> getParameterTypes(Method method, String[] parameterPaths) { Map<String,Class<?>> result = new HashMap<String, Class<?>>(); String[] parameterNamesFor = provider.parameterNamesFor(method); for (String path : parameterPaths) { for (int i = 0; i < parameterNamesFor.length; i++) { String name = parameterNamesFor[i]; if (path.startsWith(name + '.') || path.equals(name)) { String[] items = path.split("\\."); Class<?> type = method.getParameterTypes()[i]; for (int j = 1; j < items.length; j++) { String item = items[j]; try { type = new Mirror().on(type).reflect().method("get" + upperFirst(item)).withoutArgs().getReturnType(); } catch (Exception e) { throw new IllegalArgumentException("Parameters paths are invalid: " + Arrays.toString(parameterPaths) + " for method " + method, e); } } result.put(path, type); } } } return result; } DefaultTypeFinder(ParameterNameProvider provider); Map<String, Class<?>> getParameterTypes(Method method, String[] parameterPaths);  }
@Test public void shouldGetTypesCorrectly() throws Exception { final Method method = new Mirror().on(AController.class).reflect().method("aMethod").withArgs(Bean.class, String.class); when(provider.parameterNamesFor(method)).thenReturn(new String[] {"bean", "path"}); DefaultTypeFinder finder = new DefaultTypeFinder(provider); Map<String, Class<?>> types = finder.getParameterTypes(method, new String[] {"bean.bean2.id", "path"}); assertEquals(Integer.class, types.get("bean.bean2.id")); assertEquals(String.class, types.get("path")); }
@Test public void shouldGetTypesCorrectlyOnInheritance() throws Exception { final Method method = new Mirror().on(AController.class).reflect().method("otherMethod").withArgs(BeanExtended.class); when(provider.parameterNamesFor(method)).thenReturn(new String[] {"extended"}); DefaultTypeFinder finder = new DefaultTypeFinder(provider); Map<String, Class<?>> types = finder.getParameterTypes(method, new String[] {"extended.id"}); assertEquals(Integer.class, types.get("extended.id")); }