diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index ee8bb7049e9..e96427c6747 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -165,7 +165,7 @@ 1.23 7.7.2 - 5.1.12.RELEASE + 5.1.13.BUILD-SNAPSHOT 2.1.12.RELEASE 4.1.3.RELEASE 2.0.7.RELEASE diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java index bf096bea33c..a0cf6bd948d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java @@ -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 Bindable> getMapBindable(Class 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> addresses; + + public Map> getAddresses() { + return this.addresses; + } + + public void setAddresses(Map> addresses) { + this.addresses = addresses; + } + + } + }