Commit 24dd416f authored by Madhura Bhave's avatar Madhura Bhave

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
parent 8ddcb931
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
<snakeyaml.version>1.23</snakeyaml.version> <snakeyaml.version>1.23</snakeyaml.version>
<solr.version>7.7.2</solr.version> <solr.version>7.7.2</solr.version>
<!-- deprecated in favor of "spring-framework.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-amqp.version>2.1.12.RELEASE</spring-amqp.version>
<spring-batch.version>4.1.3.RELEASE</spring-batch.version> <spring-batch.version>4.1.3.RELEASE</spring-batch.version>
<spring-cloud-connectors.version>2.0.7.RELEASE</spring-cloud-connectors.version> <spring-cloud-connectors.version>2.0.7.RELEASE</spring-cloud-connectors.version>
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.boot.context.properties.bind; package org.springframework.boot.context.properties.bind;
import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
...@@ -598,6 +599,18 @@ public class MapBinderTests { ...@@ -598,6 +599,18 @@ public class MapBinderTests {
assertThat(result.getValues()).containsExactly(entry("a", "b")); 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) { private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric, ResolvableType valueType) {
ResolvableType keyType = ResolvableType.forClass(keyGeneric); ResolvableType keyType = ResolvableType.forClass(keyGeneric);
return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType)); return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType));
...@@ -713,4 +726,18 @@ public class MapBinderTests { ...@@ -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;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment