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
d1e1a82b
Commit
d1e1a82b
authored
Jan 02, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support binding to collection with EnumSet values
Fixes gh-15539
parent
d000f3bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletion
+29
-1
CollectionBinder.java
...mework/boot/context/properties/bind/CollectionBinder.java
+2
-1
CollectionBinderTests.java
...k/boot/context/properties/bind/CollectionBinderTests.java
+27
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/CollectionBinder.java
View file @
d1e1a82b
...
@@ -46,7 +46,8 @@ class CollectionBinder extends IndexedElementsBinder<Collection<Object>> {
...
@@ -46,7 +46,8 @@ class CollectionBinder extends IndexedElementsBinder<Collection<Object>> {
target
.
getType
().
asCollection
().
getGenerics
());
target
.
getType
().
asCollection
().
getGenerics
());
ResolvableType
elementType
=
target
.
getType
().
asCollection
().
getGeneric
();
ResolvableType
elementType
=
target
.
getType
().
asCollection
().
getGeneric
();
IndexedCollectionSupplier
result
=
new
IndexedCollectionSupplier
(
IndexedCollectionSupplier
result
=
new
IndexedCollectionSupplier
(
()
->
CollectionFactory
.
createCollection
(
collectionType
,
0
));
()
->
CollectionFactory
.
createCollection
(
collectionType
,
elementType
.
resolve
(),
0
));
bindIndexed
(
name
,
target
,
elementBinder
,
aggregateType
,
elementType
,
result
);
bindIndexed
(
name
,
target
,
elementBinder
,
aggregateType
,
elementType
,
result
);
if
(
result
.
wasSupplied
())
{
if
(
result
.
wasSupplied
())
{
return
result
.
get
();
return
result
.
get
();
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java
View file @
d1e1a82b
...
@@ -18,6 +18,7 @@ package org.springframework.boot.context.properties.bind;
...
@@ -18,6 +18,7 @@ package org.springframework.boot.context.properties.bind;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.EnumSet
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -27,6 +28,7 @@ import java.util.stream.Collectors;
...
@@ -27,6 +28,7 @@ import java.util.stream.Collectors;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.context.properties.bind.BinderTests.ExampleEnum
;
import
org.springframework.boot.context.properties.bind.BinderTests.JavaBean
;
import
org.springframework.boot.context.properties.bind.BinderTests.JavaBean
;
import
org.springframework.boot.context.properties.source.ConfigurationProperty
;
import
org.springframework.boot.context.properties.source.ConfigurationProperty
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySource
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySource
;
...
@@ -448,6 +450,17 @@ public class CollectionBinderTests {
...
@@ -448,6 +450,17 @@ public class CollectionBinderTests {
assertThat
(
result
.
getValues
()).
containsExactly
(
"a"
,
"b"
,
"c"
);
assertThat
(
result
.
getValues
()).
containsExactly
(
"a"
,
"b"
,
"c"
);
}
}
@Test
public
void
bindToBeanWithEnumSetCollection
()
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"foo.values[0]"
,
"foo-bar,bar-baz"
);
this
.
sources
.
add
(
source
);
BeanWithEnumsetCollection
result
=
this
.
binder
.
bind
(
"foo"
,
Bindable
.
of
(
BeanWithEnumsetCollection
.
class
)).
get
();
assertThat
(
result
.
getValues
().
get
(
0
)).
containsExactly
(
ExampleEnum
.
FOO_BAR
,
ExampleEnum
.
BAR_BAZ
);
}
public
static
class
ExampleCollectionBean
{
public
static
class
ExampleCollectionBean
{
private
List
<
String
>
items
=
new
ArrayList
<>();
private
List
<
String
>
items
=
new
ArrayList
<>();
...
@@ -566,4 +579,18 @@ public class CollectionBinderTests {
...
@@ -566,4 +579,18 @@ public class CollectionBinderTests {
}
}
public
static
class
BeanWithEnumsetCollection
{
private
List
<
EnumSet
<
ExampleEnum
>>
values
;
public
void
setValues
(
List
<
EnumSet
<
ExampleEnum
>>
values
)
{
this
.
values
=
values
;
}
public
List
<
EnumSet
<
ExampleEnum
>>
getValues
()
{
return
this
.
values
;
}
}
}
}
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