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
efda5ef3
Commit
efda5ef3
authored
May 11, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
1afab3a8
3992dacd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
IndexedElementsBinder.java
...k/boot/context/properties/bind/IndexedElementsBinder.java
+13
-5
CollectionBinderTests.java
...k/boot/context/properties/bind/CollectionBinderTests.java
+13
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java
View file @
efda5ef3
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.context.properties.bind;
import
java.lang.annotation.Annotation
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.TreeSet
;
import
java.util.function.Supplier
;
...
...
@@ -32,6 +33,7 @@ import org.springframework.boot.context.properties.source.IterableConfigurationP
import
org.springframework.core.ResolvableType
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.StringUtils
;
/**
* Base class for {@link AggregateBinder AggregateBinders} that read a sequential run of
...
...
@@ -81,11 +83,17 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
ResolvableType
aggregateType
,
ResolvableType
elementType
)
{
ConfigurationProperty
property
=
source
.
getConfigurationProperty
(
root
);
if
(
property
!=
null
)
{
Object
aggregate
=
convert
(
property
.
getValue
(),
aggregateType
,
target
.
getAnnotations
());
ResolvableType
collectionType
=
ResolvableType
.
forClassWithGenerics
(
collection
.
get
().
getClass
(),
elementType
);
Collection
<
Object
>
elements
=
convert
(
aggregate
,
collectionType
);
Collection
<
Object
>
elements
;
Object
value
=
property
.
getValue
();
if
(
value
instanceof
String
&&
!
StringUtils
.
hasText
((
String
)
value
))
{
elements
=
Collections
.
emptyList
();
}
else
{
Object
aggregate
=
convert
(
value
,
aggregateType
,
target
.
getAnnotations
());
ResolvableType
collectionType
=
ResolvableType
.
forClassWithGenerics
(
collection
.
get
().
getClass
(),
elementType
);
elements
=
convert
(
aggregate
,
collectionType
);
}
collection
.
get
().
addAll
(
elements
);
}
else
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java
View file @
efda5ef3
...
...
@@ -363,6 +363,19 @@ public class CollectionBinderTests {
assertThat
(
foo
.
getFoos
().
get
(
1
).
getValue
()).
isEqualTo
(
"three"
);
}
@Test
public
void
bindToNestedCollectionWhenEmptyStringShouldReturnEmptyCollection
()
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"foo.value"
,
"one"
);
source
.
put
(
"foo.foos"
,
""
);
this
.
sources
.
add
(
source
);
Bindable
<
BeanWithNestedCollection
>
target
=
Bindable
.
of
(
BeanWithNestedCollection
.
class
);
BeanWithNestedCollection
foo
=
this
.
binder
.
bind
(
"foo"
,
target
).
get
();
assertThat
(
foo
.
getValue
()).
isEqualTo
(
"one"
);
assertThat
(
foo
.
getFoos
()).
isEmpty
();
}
@Test
public
void
bindToCollectionShouldUsePropertyEditor
()
{
// gh-12166
...
...
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