Add a test case for binding to map with wildcard types
This commit also changes the spring framework version to use snapshots. Closes gh-18767
This commit is contained in:
@@ -165,7 +165,7 @@
|
||||
<snakeyaml.version>1.23</snakeyaml.version>
|
||||
<solr.version>7.7.2</solr.version>
|
||||
<!-- deprecated in favor of "spring-framework.version" -->
|
||||
<spring.version>5.1.12.RELEASE</spring.version>
|
||||
<spring.version>5.1.13.BUILD-SNAPSHOT</spring.version>
|
||||
<spring-amqp.version>2.1.12.RELEASE</spring-amqp.version>
|
||||
<spring-batch.version>4.1.3.RELEASE</spring-batch.version>
|
||||
<spring-cloud-connectors.version>2.0.7.RELEASE</spring-cloud-connectors.version>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.context.properties.bind;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -598,6 +599,18 @@ public class MapBinderTests {
|
||||
assertThat(result.getValues()).containsExactly(entry("a", "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindToMapWithWildcardShouldConvertToTheRightType() {
|
||||
// gh-18767
|
||||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
||||
source.put("foo.addresses.localhost[0]", "127.0.0.1");
|
||||
source.put("foo.addresses.localhost[1]", "127.0.0.2");
|
||||
this.sources.add(source);
|
||||
MapWithWildcardProperties result = this.binder.bind("foo", Bindable.of(MapWithWildcardProperties.class)).get();
|
||||
assertThat(result.getAddresses().get("localhost").stream().map(InetAddress::getHostAddress))
|
||||
.containsExactly("127.0.0.1", "127.0.0.2");
|
||||
}
|
||||
|
||||
private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric, ResolvableType valueType) {
|
||||
ResolvableType keyType = ResolvableType.forClass(keyGeneric);
|
||||
return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType));
|
||||
@@ -713,4 +726,18 @@ public class MapBinderTests {
|
||||
|
||||
}
|
||||
|
||||
public static class MapWithWildcardProperties {
|
||||
|
||||
private Map<String, ? extends List<? extends InetAddress>> addresses;
|
||||
|
||||
public Map<String, ? extends List<? extends InetAddress>> getAddresses() {
|
||||
return this.addresses;
|
||||
}
|
||||
|
||||
public void setAddresses(Map<String, ? extends List<? extends InetAddress>> addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user