Issue Details (XML | Word | Printable)

Key: SPR-4313
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Paul Middelkoop
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring Framework

@RequestParam does't work with generics

Created: 10/Jan/08 04:41 AM   Updated: 14/Feb/08 03:09 AM
Component/s: SpringWEB
Affects Version/s: 2.5 final, 2.5.1
Fix Version/s: 2.5.2

Time Tracking:
Not Specified

Virtual Machine: Sun JVM - 1.5
Platform: Tomcat - 5.5


 Description  « Hide
It seems like I can't use a generic type as @RequestParam. Spring converts the parameter to a org.springframework.ui.ExtendedModelMap instead of the correct generic type.

Example:

public abstract class CrudController<T extends Entity<ID>, ID extends Serializable> {
    @RequestMapping(params = "action=delete", method = RequestMethod.GET)
    public String delete(@RequestParam("id") ID id) {..}
}

public class QuestionControlller extends ToolboxCrudController<Question, Integer> {
}

It should be possible for Spring MVC to notice that ID should be a Integer right?

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Paul Middelkoop added a comment - 10/Jan/08 07:58 AM
The problem seems to be that ArgumentsResolver.resolveArguments does a incorrect check: param.getParameterType().isInstance(implicitModel).
In my case the parameter is a Serializable. Since ExtendedModelMap is also a Serializable this returns true. I will comment again I made a fix.

Paul Middelkoop added a comment - 10/Jan/08 11:25 AM
I think that specific line in ArgumentsResolver should be ExtendedModelMap.class.isAssignableFrom(param.getParameterType()).
I guess because of erasure you cannot get the type of a generic method parameter. Shame.

Juergen Hoeller added a comment - 17/Jan/08 08:32 AM
Good news: We actually can resolve generic type variables as long as they are statically declared in subclasses (like in your case)! I've added full support for such generic types in handler method signatures, to be released in Spring 2.5.2.

I've taken this occasion to do some general refactoring of the AnnotationMethodHandlerAdapter classes. The Servlet and Portlet variants share their common code as far as feasible now, in particular with respect to method argument resolution.

This revision will be available in the next 2.5.2 snapshot (-374 or higher; available from http://static.springframework.org/downloads/nightly/snapshot-download.php?project=SPR). Please give it a try and let us know whether it works for you...

Thanks for raising this!

Juergen

Paul Middelkoop added a comment - 18/Jan/08 09:07 AM
Sorry but it doesn't work in the nightly build 20080117-374. Since my generic parameter is Serializable I still get a ExtendedModelMap instead of an Integer. If I change in ArgumentsResolver.resolveArguments() to ExtendedModelMap.class.isAssignableFrom(param.getParameterType() I get an array of Strings because of paramValue = request.getParameterValues(paramName). I expect an Integer...

Juergen Hoeller added a comment - 18/Jan/08 09:11 AM
Unfortunately this revision hasn't made it into CVS yet due to SourceForge problems... SourceForge's developer CVS has been down for nearly two days. As a consequence, build 374 still contains the "old" code. I'll let you know when the changes are actually in the nightly build!

Sorry for the incovenience...

Juergen

Paul Middelkoop added a comment - 14/Feb/08 03:09 AM
Works fine in the latest build. Great job!