Skip to content

Commit d4a23b8

Browse files
committed
Properties values get properly converted to generic Map types (fixing 4.x regression without use of ConversionService)
Issue: SPR-13256
1 parent acc8c89 commit d4a23b8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ private Collection<?> convertToTypedCollection(
521521
}
522522

523523
boolean originalAllowed = requiredType.isInstance(original);
524-
typeDescriptor = typeDescriptor.narrow(original);
525524
TypeDescriptor elementType = typeDescriptor.getElementTypeDescriptor();
526525
if (elementType == null && originalAllowed &&
527526
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
@@ -603,7 +602,6 @@ private Collection<?> convertToTypedCollection(
603602
}
604603

605604
boolean originalAllowed = requiredType.isInstance(original);
606-
typeDescriptor = typeDescriptor.narrow(original);
607605
TypeDescriptor keyType = typeDescriptor.getMapKeyTypeDescriptor();
608606
TypeDescriptor valueType = typeDescriptor.getMapValueTypeDescriptor();
609607
if (keyType == null && valueType == null && originalAllowed &&

spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
import java.util.LinkedList;
2727
import java.util.List;
2828
import java.util.Map;
29+
import java.util.Properties;
2930
import java.util.Set;
3031

3132
import org.junit.Test;
@@ -182,6 +183,18 @@ public void testGenericMapElementWithCollectionValue() {
182183
assertTrue(gb.getCollectionMap().get(new Integer(1)) instanceof HashSet);
183184
}
184185

186+
@Test
187+
public void testGenericMapFromProperties() {
188+
GenericBean<?> gb = new GenericBean<Object>();
189+
BeanWrapper bw = new BeanWrapperImpl(gb);
190+
Properties input = new Properties();
191+
input.setProperty("4", "5");
192+
input.setProperty("6", "7");
193+
bw.setPropertyValue("shortMap", input);
194+
assertEquals(new Integer(5), gb.getShortMap().get(new Short("4")));
195+
assertEquals(new Integer(7), gb.getShortMap().get(new Short("6")));
196+
}
197+
185198
@Test
186199
public void testGenericListOfLists() throws MalformedURLException {
187200
GenericBean<String> gb = new GenericBean<String>();

0 commit comments

Comments
 (0)