diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java b/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java index 231a3a7781f..f520d6fb654 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java @@ -572,8 +572,7 @@ class TypeConverterDelegate { if (methodParam != null) { methodParam.increaseNestingLevel(); } - Object convertedElement = - convertIfNecessary(indexedPropertyName, null, element, elementType, typeDescriptor); + Object convertedElement = convertIfNecessary(indexedPropertyName, null, element, elementType); if (methodParam != null) { methodParam.decreaseNestingLevel(); } @@ -652,11 +651,11 @@ class TypeConverterDelegate { methodParam.increaseNestingLevel(); methodParam.setTypeIndexForCurrentLevel(0); } - Object convertedKey = convertIfNecessary(keyedPropertyName, null, key, keyType, typeDescriptor); + Object convertedKey = convertIfNecessary(keyedPropertyName, null, key, keyType); if (methodParam != null) { methodParam.setTypeIndexForCurrentLevel(1); } - Object convertedValue = convertIfNecessary(keyedPropertyName, null, value, valueType, typeDescriptor); + Object convertedValue = convertIfNecessary(keyedPropertyName, null, value, valueType); if (methodParam != null) { methodParam.decreaseNestingLevel(); } diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/beans/GenericBean.java b/org.springframework.web.servlet/src/test/java/org/springframework/beans/GenericBean.java index c4b85fa1f61..00dd127e47c 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/beans/GenericBean.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/beans/GenericBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,8 @@ public class GenericBean { private Set integerSet; + private Set testBeanSet; + private List resourceList; private List> listOfLists; @@ -105,6 +107,14 @@ public class GenericBean { this.integerSet = integerSet; } + public Set getTestBeanSet() { + return testBeanSet; + } + + public void setTestBeanSet(Set testBeanSet) { + this.testBeanSet = testBeanSet; + } + public List getResourceList() { return resourceList; } 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 444d2ba9162..74d3663a9cc 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 @@ -57,6 +57,7 @@ import org.springframework.aop.interceptor.SimpleTraceInterceptor; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.beans.BeansException; import org.springframework.beans.DerivedTestBean; +import org.springframework.beans.GenericBean; import org.springframework.beans.ITestBean; import org.springframework.beans.TestBean; import org.springframework.beans.factory.annotation.Autowired; @@ -66,6 +67,8 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.context.annotation.AnnotationConfigUtils; import org.springframework.core.MethodParameter; +import org.springframework.core.convert.converter.Converter; +import org.springframework.format.support.FormattingConversionServiceFactoryBean; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; @@ -104,6 +107,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.SessionAttributes; +import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; import org.springframework.web.bind.support.WebArgumentResolver; import org.springframework.web.bind.support.WebBindingInitializer; import org.springframework.web.context.WebApplicationContext; @@ -259,6 +263,33 @@ public class ServletAnnotationControllerTests { assertEquals("foo-bar-/myApp", response.getContentAsString()); } + @Test + public void typeNestedSetBinding() throws Exception { + servlet = new DispatcherServlet() { + @Override + protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { + GenericWebApplicationContext wac = new GenericWebApplicationContext(); + wac.registerBeanDefinition("controller", new RootBeanDefinition(NestedSetController.class)); + RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class); + csDef.getPropertyValues().add("converters", new TestBeanConverter()); + RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class); + wbiDef.getPropertyValues().add("conversionService", csDef); + RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class); + adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef); + wac.registerBeanDefinition("handlerAdapter", adapterDef); + wac.refresh(); + return wac; + } + }; + servlet.init(new MockServletConfig()); + + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do"); + request.addParameter("testBeanSet", new String[] {"1", "2"}); + MockHttpServletResponse response = new MockHttpServletResponse(); + servlet.service(request, response); + assertEquals("[1, 2]-org.springframework.beans.TestBean", response.getContentAsString()); + } + @Test public void methodNotAllowed() throws Exception { initServlet(MethodNotAllowedController.class); @@ -1666,6 +1697,7 @@ public class ServletAnnotationControllerTests { public String post(@ModelAttribute("object1") Object object1) { //do something with object1 return "myPage"; + } } @@ -2172,6 +2204,23 @@ public class ServletAnnotationControllerTests { } } + @Controller + public static class NestedSetController { + + @RequestMapping("/myPath.do") + public void myHandle(GenericBean gb, HttpServletResponse response) throws Exception { + response.getWriter().write(gb.getTestBeanSet().toString() + "-" + + gb.getTestBeanSet().iterator().next().getClass().getName()); + } + } + + public static class TestBeanConverter implements Converter { + + public ITestBean convert(String source) { + return new TestBean(source); + } + } + @Controller public static class MethodNotAllowedController { @@ -2568,8 +2617,6 @@ public class ServletAnnotationControllerTests { public void handle(@RequestParam("map") Map map, Writer writer) throws IOException { writer.write("test-" + map); } - - } public static class CustomMapEditor extends PropertyEditorSupport {