Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
90ddd857
Commit
90ddd857
authored
Oct 20, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for binding to Properties in @ConfigurationProperties
Fixes gh-4250
parent
b7641400
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
10 deletions
+36
-10
pom.xml
spring-boot-dependencies/pom.xml
+1
-1
RelaxedDataBinder.java
...java/org/springframework/boot/bind/RelaxedDataBinder.java
+5
-0
RelaxedDataBinderTests.java
...org/springframework/boot/bind/RelaxedDataBinderTests.java
+30
-9
No files found.
spring-boot-dependencies/pom.xml
100755 → 100644
View file @
90ddd857
...
...
@@ -2185,4 +2185,4 @@
<id>
integration-test
</id>
</profile>
</profiles>
</project>
</project>
\ No newline at end of file
spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java
View file @
90ddd857
...
...
@@ -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<Object,Object> but we know it's really Map<String,String>
return
true
;
}
Class
<?>
valueType
=
descriptor
.
getMapValueTypeDescriptor
().
getObjectType
();
return
(
valueType
!=
null
&&
CharSequence
.
class
.
isAssignableFrom
(
valueType
));
}
...
...
spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java
View file @
90ddd857
...
...
@@ -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
<
String
,
String
>
nested
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment