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
6b3329b2
Commit
6b3329b2
authored
Jun 11, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for annotations on constructor parameter binding
Closes gh-17109
parent
e6151a64
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
ConstructorParametersBinder.java
.../context/properties/bind/ConstructorParametersBinder.java
+1
-1
ConstructorParametersBinderTests.java
...ext/properties/bind/ConstructorParametersBinderTests.java
+26
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ConstructorParametersBinder.java
View file @
6b3329b2
...
...
@@ -83,7 +83,7 @@ class ConstructorParametersBinder implements BeanBinder {
private
Object
bind
(
ConstructorParameter
parameter
,
BeanPropertyBinder
propertyBinder
)
{
String
propertyName
=
parameter
.
getName
();
ResolvableType
type
=
parameter
.
getType
();
return
propertyBinder
.
bindProperty
(
propertyName
,
Bindable
.
of
(
type
));
return
propertyBinder
.
bindProperty
(
propertyName
,
Bindable
.
of
(
type
)
.
withAnnotations
(
parameter
.
getAnnotations
())
);
}
private
static
final
class
Bean
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ConstructorParametersBinderTests.java
View file @
6b3329b2
...
...
@@ -15,6 +15,7 @@
*/
package
org
.
springframework
.
boot
.
context
.
properties
.
bind
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -23,6 +24,7 @@ import org.junit.jupiter.api.Test;
import
org.springframework.boot.context.properties.source.ConfigurationPropertyName
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySource
;
import
org.springframework.boot.context.properties.source.MockConfigurationPropertySource
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -137,6 +139,16 @@ class ConstructorParametersBinderTests {
assertThat
(
bean
.
getCustomList
()).
containsOnly
(
"x,y,z"
);
}
@Test
void
bindWithAnnotations
()
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"foo.date"
,
"2014-04-01"
);
this
.
sources
.
add
(
source
);
ConverterAnnotatedExampleBean
bean
=
this
.
binder
.
bind
(
"foo"
,
Bindable
.
of
(
ConverterAnnotatedExampleBean
.
class
))
.
get
();
assertThat
(
bean
.
getDate
().
toString
()).
isEqualTo
(
"2014-04-01"
);
}
public
static
class
ExampleValueBean
{
private
final
int
intValue
;
...
...
@@ -265,4 +277,18 @@ class ConstructorParametersBinderTests {
}
public
static
class
ConverterAnnotatedExampleBean
{
private
final
LocalDate
date
;
ConverterAnnotatedExampleBean
(
@DateTimeFormat
(
iso
=
DateTimeFormat
.
ISO
.
DATE
)
LocalDate
date
)
{
this
.
date
=
date
;
}
public
LocalDate
getDate
()
{
return
this
.
date
;
}
}
}
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