Skip to content

Commit 24dd416

Browse files
committed
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
1 parent 8ddcb93 commit 24dd416

File tree

2 files changed

+28
-1
lines changed
  • spring-boot-project

2 files changed

+28
-1
lines changed

spring-boot-project/spring-boot-dependencies/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
<snakeyaml.version>1.23</snakeyaml.version>
166166
<solr.version>7.7.2</solr.version>
167167
<!-- deprecated in favor of "spring-framework.version" -->
168-
<spring.version>5.1.12.RELEASE</spring.version>
168+
<spring.version>5.1.13.BUILD-SNAPSHOT</spring.version>
169169
<spring-amqp.version>2.1.12.RELEASE</spring-amqp.version>
170170
<spring-batch.version>4.1.3.RELEASE</spring-batch.version>
171171
<spring-cloud-connectors.version>2.0.7.RELEASE</spring-cloud-connectors.version>

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.context.properties.bind;
1818

19+
import java.net.InetAddress;
1920
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.HashMap;
@@ -598,6 +599,18 @@ public void bindToBeanWithExceptionInGetterForExistingValue() {
598599
assertThat(result.getValues()).containsExactly(entry("a", "b"));
599600
}
600601

602+
@Test
603+
public void bindToMapWithWildcardShouldConvertToTheRightType() {
604+
// gh-18767
605+
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
606+
source.put("foo.addresses.localhost[0]", "127.0.0.1");
607+
source.put("foo.addresses.localhost[1]", "127.0.0.2");
608+
this.sources.add(source);
609+
MapWithWildcardProperties result = this.binder.bind("foo", Bindable.of(MapWithWildcardProperties.class)).get();
610+
assertThat(result.getAddresses().get("localhost").stream().map(InetAddress::getHostAddress))
611+
.containsExactly("127.0.0.1", "127.0.0.2");
612+
}
613+
601614
private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric, ResolvableType valueType) {
602615
ResolvableType keyType = ResolvableType.forClass(keyGeneric);
603616
return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType));
@@ -713,4 +726,18 @@ public Map<String, String> getValues() {
713726

714727
}
715728

729+
public static class MapWithWildcardProperties {
730+
731+
private Map<String, ? extends List<? extends InetAddress>> addresses;
732+
733+
public Map<String, ? extends List<? extends InetAddress>> getAddresses() {
734+
return this.addresses;
735+
}
736+
737+
public void setAddresses(Map<String, ? extends List<? extends InetAddress>> addresses) {
738+
this.addresses = addresses;
739+
}
740+
741+
}
742+
716743
}

0 commit comments

Comments
 (0)