diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index 3128397fff..38c72904ff 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -189,7 +189,7 @@ 4.2.1.RELEASE 2.0.7.RELEASE Moore-SR3 - 5.2.2.RELEASE + 5.2.3.BUILD-SNAPSHOT 1.0.2.RELEASE 5.2.2.RELEASE 2.3.4.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 ab55fd70e7..f06a03bd60 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; @@ -592,6 +593,18 @@ 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)); @@ -707,4 +720,18 @@ class MapBinderTests { } + static class MapWithWildcardProperties { + + private Map> addresses; + + Map> getAddresses() { + return this.addresses; + } + + void setAddresses(Map> addresses) { + this.addresses = addresses; + } + + } + }