diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java index 38547d30546..444d2ba9162 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java @@ -16,6 +16,7 @@ package org.springframework.web.servlet.mvc.annotation; +import java.beans.PropertyEditorSupport; import java.io.IOException; import java.io.Serializable; import java.io.UnsupportedEncodingException; @@ -1473,6 +1474,22 @@ public class ServletAnnotationControllerTests { assertEquals("templatePath", response.getContentAsString()); } + /* + * See SPR-6021 + */ + @Test + public void customMapEditor() throws Exception { + initServlet(CustomMapEditorController.class); + + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/handle"); + request.addParameter("map", "bar"); + MockHttpServletResponse response = new MockHttpServletResponse(); + + servlet.service(request, response); + + assertEquals("test-{foo=bar}", response.getContentAsString()); + } + /* * Controllers */ @@ -2538,5 +2555,36 @@ public class ServletAnnotationControllerTests { } } + @Controller + public static class CustomMapEditorController { + + @InitBinder + public void initBinder(WebDataBinder binder) { + binder.initBeanPropertyAccess(); + binder.registerCustomEditor(Map.class, new CustomMapEditor()); + } + + @RequestMapping("/handle") + public void handle(@RequestParam("map") Map map, Writer writer) throws IOException { + writer.write("test-" + map); + } + + + } + + public static class CustomMapEditor extends PropertyEditorSupport { + + @Override + public void setAsText(String text) throws IllegalArgumentException { + if (StringUtils.hasText(text)) { + setValue(Collections.singletonMap("foo", text)); + } + else { + setValue(null); + } + } + + } + } diff --git a/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java b/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java index 7475d18036a..a3bedef15fc 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java +++ b/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java @@ -419,7 +419,7 @@ public class HandlerMethodInvoker { throws Exception { Class paramType = methodParam.getParameterType(); - if (Map.class.isAssignableFrom(paramType)) { + if (Map.class.isAssignableFrom(paramType) && paramName.length() == 0) { return resolveRequestParamMap((Class) paramType, webRequest); } if (paramName.length() == 0) {