diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml old mode 100755 new mode 100644 index 083b7bfcf5f..6cf210040c9 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -2185,4 +2185,4 @@ integration-test - + \ No newline at end of file diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java index ef592a3b67f..06f95554280 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java @@ -25,6 +25,7 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import org.springframework.beans.BeanWrapper; @@ -311,6 +312,10 @@ public class RelaxedDataBinder extends DataBinder { if (descriptor == null || descriptor.getMapValueTypeDescriptor() == null) { return false; } + if (Properties.class.isAssignableFrom(descriptor.getObjectType())) { + // Properties is declared as Map but we know it's really Map + return true; + } Class valueType = descriptor.getMapValueTypeDescriptor().getObjectType(); return (valueType != null && CharSequence.class.isAssignableFrom(valueType)); } diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java index 72f3dc089ee..8879573b089 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java @@ -16,6 +16,14 @@ package org.springframework.boot.bind; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -40,7 +48,6 @@ import javax.validation.constraints.NotNull; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.NotWritablePropertyException; import org.springframework.context.support.StaticMessageSource; @@ -53,14 +60,6 @@ import org.springframework.validation.DataBinder; import org.springframework.validation.FieldError; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - /** * Tests for {@link RelaxedDataBinder}. * @@ -371,6 +370,14 @@ public class RelaxedDataBinderTests { assertEquals("123", target.getNested().get("value.foo")); } + @Test + public void testBindNestedProperties() throws Exception { + TargetWithNestedProperties target = new TargetWithNestedProperties(); + bind(target, "nested.foo: bar\n" + "nested.value.foo: 123"); + assertEquals("bar", target.getNested().get("foo")); + assertEquals("123", target.getNested().get("value.foo")); + } + @Test public void testBindNestedMapOfEnum() throws Exception { this.conversionService = new DefaultConversionService(); @@ -780,6 +787,20 @@ public class RelaxedDataBinderTests { } + public static class TargetWithNestedProperties { + + private Properties nested; + + public Properties getNested() { + return this.nested; + } + + public void setNested(Properties nested) { + this.nested = nested; + } + + } + public static class TargetWithNestedMapOfString { private Map nested;