-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MapMethodProcessor
should only resolve arguments of type Map or the ModelMap hierarchy
#33160
Comments
MapMethodArgumentResolver
precludes custom argument resolver when using Map
subtype
Hi @effad, Congratulations on submitting your first issue for the Spring Framework! 👍
That seems like a reasonable assumption, and we'll investigate that approach.
Doing that alone unfortunately breaks existing support for Thus, if we "flip the type check" in If we decide to make such changes, we'll also want to make sure that use cases like your |
The following change in @Override
public boolean supportsParameter(MethodParameter parameter) {
return ((parameter.getParameterType().isAssignableFrom(Map.class) ||
ModelMap.class.isAssignableFrom(parameter.getParameterType())) &&
parameter.getParameterAnnotations().length == 0);
} |
FWIW I have worked around the problem for the moment, by putting my own @Override
protected RequestMappingHandlerAdapter createRequestMappingHandlerAdapter() {
return new RequestMappingHandlerAdapter() {
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(getArgumentResolvers());
resolvers.add(0, payloadMethodArgumentResolver());
setArgumentResolvers(resolvers);
}
};
} This feels quite hacky, though :-). |
@sbrannen I think this would be fine #33160 (comment). The goal is to be able to inject |
MapMethodArgumentResolver
precludes custom argument resolver when using Map
subtypeMapMethodProcessor
precludes custom argument resolver when using Map
subtype
Moving this to 6.2.x since we are not likely to resolve it for this week anymore, and there is a significant risk for side effects. |
MapMethodProcessor
precludes custom argument resolver when using Map
subtypeMapMethodProcessor
should resolve only Map or subtypes of ModelMap only
MapMethodProcessor
should resolve only Map or subtypes of ModelMap onlyMapMethodProcessor
should only resolve arguments of type Map or the ModelMap hierarchy
Affects: 6.1.6
This is a slight variation of SPR-17340 (#21874) that I've run into.
I have a
Payload
class that derives fromMap<String, Object>
:And a method argument resolver for it:
I want to use it like this:
Note that there is no annotation before
Payload
(it should not be necessary, since we have a custom type with a custom argument resolver. But, since there is no way to add my resolver to the top of the resolver list (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.getDefaultArgumentResolvers()
), theMapMethodProcessor
will be used, returning an emptyBindingAwareModelMap
. Since this does not match the required type ofcreateHost
, anIllegalArgumentException
will be thrown inorg.springframework.web.method.support.InvocableHandlerMethod.doInvoke(Object...)
.I think the problem lies in
org.springframework.web.method.annotation.MapMethodProcessor.supportsParameter(MethodParameter)
, which should not claim support for every subtype of Map (as it currently does). If the type check would be flipped like this, I think it should work correctly:Only if the type of the parameter can be assigned a
Map
should theMapMethodProcessor
be applied.Related Issues
The text was updated successfully, but these errors were encountered: