Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.boot.context.properties.source.IterableConfigurationPropertySource;
import org.springframework.core.CollectionFactory;
import org.springframework.core.ResolvableType;
import org.springframework.util.ObjectUtils;

/**
* {@link AggregateBinder} for Maps.
Expand Down Expand Up @@ -64,6 +65,9 @@ protected boolean isAllowRecursiveBinding(@Nullable ConfigurationPropertySource
if (property != null) {
getContext().setConfigurationProperty(property);
Object result = getContext().getPlaceholdersResolver().resolvePlaceholders(property.getValue());
if (ObjectUtils.isEmpty(result)) {
return createMap(target);
}
return getContext().getConverter().convert(result, target);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ void bindToMapWhenNoValueShouldReturnUnbound() {
assertThat(result.isBound()).isFalse();
}

@Test
void bindToMapWhenEmptyStringShouldReturnEmptyMap() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo", "");
this.sources.add(source);
Map<String, String> result = this.binder.bind("foo", STRING_STRING_MAP).get();
assertThat(result).isEmpty();
}

@Test
void bindToMapShouldConvertKey() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
Expand Down Expand Up @@ -510,6 +519,17 @@ void nestedMapsShouldNotBindToNull() {
assertThat(foo2.getValue()).isEqualTo("three");
}

@Test
void nestedMapsWhenEmptyStringShouldReturnEmptyMap() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value", "one");
source.put("foo.foos", "");
this.sources.add(source);
BindResult<NestableFoo> foo = this.binder.bind("foo", NestableFoo.class);
assertThat(foo.get().getValue()).isEqualTo("one");
assertThat(foo.get().getFoos()).isEmpty();
}

@Test
void bindToMapWithCustomConverter() {
DefaultConversionService conversionService = new DefaultConversionService();
Expand Down
Loading