Commit e6409083 authored by Madhura Bhave's avatar Madhura Bhave

Revert "Nested Map should not bind to null"

This reverts commit 54065677.
parent 54065677
......@@ -298,10 +298,11 @@ public class Binder {
}
BeanPropertyBinder propertyBinder = (propertyName, propertyTarget) -> bind(
name.append(propertyName), propertyTarget, handler, context);
if (context.isProcessingName(name)) {
Class<?> type = target.getType().resolve();
if (context.hasBoundBean(type)) {
return null;
}
return context.withName(name, () -> {
return context.withBean(type, () -> {
Stream<?> boundBeans = BEAN_BINDERS.stream()
.map((b) -> b.bind(name, target, context, propertyBinder));
return boundBeans.filter(Objects::nonNull).findFirst().orElse(null);
......@@ -352,7 +353,7 @@ public class Binder {
private final List<ConfigurationPropertySource> source = Arrays
.asList((ConfigurationPropertySource) null);
private final Deque<ConfigurationPropertyName> names = new ArrayDeque<>();
private final Deque<Class<?>> beans = new ArrayDeque<>();
private ConfigurationProperty configurationProperty;
......@@ -384,13 +385,13 @@ public class Binder {
}
}
public <T> T withName(ConfigurationPropertyName name, Supplier<T> supplier) {
this.names.push(name);
public <T> T withBean(Class<?> bean, Supplier<T> supplier) {
this.beans.push(bean);
try {
return withIncreasedDepth(supplier);
}
finally {
this.names.pop();
this.beans.pop();
}
}
......@@ -420,8 +421,8 @@ public class Binder {
return StreamSupport.stream(Binder.this.sources.spliterator(), false);
}
public boolean isProcessingName(ConfigurationPropertyName name) {
return this.names.contains(name);
public boolean hasBoundBean(Class<?> bean) {
return this.beans.contains(bean);
}
@Override
......
......@@ -19,9 +19,7 @@ package org.springframework.boot.context.properties.bind;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.assertj.core.matcher.AssertionMatcher;
import org.junit.Before;
......@@ -239,19 +237,6 @@ public class BinderTests {
this.binder.bind("foo", target);
}
@Test
public void nestedMapsShouldNotBindToNull() throws Exception {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value", "one");
source.put("foo.foos.foo1.value", "two");
source.put("foo.foos.foo2.value", "three");
this.sources.add(source);
BindResult<Foo> foo = this.binder.bind("foo", Foo.class);
assertThat(foo.get().getValue()).isNotNull();
assertThat(foo.get().getFoos().get("foo1").getValue()).isEqualTo("two");
assertThat(foo.get().getFoos().get("foo2").getValue()).isEqualTo("three");
}
public static class JavaBean {
private String value;
......@@ -278,24 +263,4 @@ public class BinderTests {
}
static class Foo {
private String value;
private Map<String, Foo> foos = new LinkedHashMap<>();
public Map<String, Foo> getFoos() {
return this.foos;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
}
}
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