diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/http/iogi/IogiParametersProvider.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/http/iogi/IogiParametersProvider.java index d731038b7..41aacc3d7 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/http/iogi/IogiParametersProvider.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/http/iogi/IogiParametersProvider.java @@ -94,7 +94,7 @@ private List> createTargets(ControllerMethod method) { for (Parameter p : nameProvider.parametersFor(javaMethod)) { Type type = p.getParameterizedType(); if (type instanceof TypeVariable) { - type = extractType(method); + type = extractType(method, (TypeVariable) type); } targets.add(new Target<>(type, p.getName())); @@ -102,10 +102,20 @@ private List> createTargets(ControllerMethod method) { return targets; } - - private Type extractType(ControllerMethod method) { - ParameterizedType superclass = (ParameterizedType) method.getController().getType().getGenericSuperclass(); - return superclass.getActualTypeArguments()[0]; + + private Type extractType(ControllerMethod method, TypeVariable paramType) { + ParameterizedType parameterizedType = (ParameterizedType) method.getController().getType().getGenericSuperclass(); + Class rawType = (Class) parameterizedType.getRawType(); + TypeVariable[] typeParameters = rawType.getTypeParameters(); + if (typeParameters.length > 0) { + for (int i = 0; i < typeParameters.length; i++) { + TypeVariable typeVariable = typeParameters[i]; + if (typeVariable.getName().equals(paramType.getName())) { + return (Class) parameterizedType.getActualTypeArguments()[i]; + } + } + } + return paramType; } private Parameters parseParameters(HttpServletRequest request) { diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/iogi/IogiParametersProviderTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/iogi/IogiParametersProviderTest.java index 4bc7af2d7..057a5a5ec 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/iogi/IogiParametersProviderTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/iogi/IogiParametersProviderTest.java @@ -148,6 +148,21 @@ public void isCapableOfDealingWithGenerics() throws Exception { assertThat(abc.x, is(123l)); } + @Test + public void isCapableOfDealingWithGenericsAndMultipleParameters() throws Exception { + requestParametersAre(ImmutableMap.of("key", new String[] { "age" }, "value", new String[] { "32" })); + + ControllerMethod generic = method(SpecificKeyValueResource.class, GenericKeyValueResource.class, "put", Object.class, Object.class); + Object[] params = iogi.getParametersFor(generic, errors); + String key = (String) params[0]; + Long value = (Long) params[1]; + + assertThat(key, is("age")); + assertThat(value, notNullValue()); + assertThat(value, instanceOf(Long.class)); + assertThat(value, is(32L)); + } + @Test public void isCapableOfDealingWithIndexedLists() throws Exception { requestParameterIs("abc[2]", "1"); @@ -602,6 +617,14 @@ void generic(T t) { } static class Specific extends Generic { } + + static class GenericKeyValueResource { + void put(K key, V value) { } + } + + static class SpecificKeyValueResource extends GenericKeyValueResource { + + } public static class Cat { private String id;