|
15 | 15 | */
|
16 | 16 | package org.springframework.boot.context.properties.bind;
|
17 | 17 |
|
| 18 | +import java.time.LocalDate; |
18 | 19 | import java.util.ArrayList;
|
19 | 20 | import java.util.List;
|
20 | 21 |
|
|
23 | 24 | import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
|
24 | 25 | import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
|
25 | 26 | import org.springframework.boot.context.properties.source.MockConfigurationPropertySource;
|
| 27 | +import org.springframework.format.annotation.DateTimeFormat; |
26 | 28 |
|
27 | 29 | import static org.assertj.core.api.Assertions.assertThat;
|
28 | 30 |
|
@@ -137,6 +139,16 @@ void bindToClassWithNoValueAndDefaultValueShouldUseDefault() {
|
137 | 139 | assertThat(bean.getCustomList()).containsOnly("x,y,z");
|
138 | 140 | }
|
139 | 141 |
|
| 142 | + @Test |
| 143 | + void bindWithAnnotations() { |
| 144 | + MockConfigurationPropertySource source = new MockConfigurationPropertySource(); |
| 145 | + source.put("foo.date", "2014-04-01"); |
| 146 | + this.sources.add(source); |
| 147 | + ConverterAnnotatedExampleBean bean = this.binder.bind("foo", Bindable.of(ConverterAnnotatedExampleBean.class)) |
| 148 | + .get(); |
| 149 | + assertThat(bean.getDate().toString()).isEqualTo("2014-04-01"); |
| 150 | + } |
| 151 | + |
140 | 152 | public static class ExampleValueBean {
|
141 | 153 |
|
142 | 154 | private final int intValue;
|
@@ -265,4 +277,18 @@ public List<String> getCustomList() {
|
265 | 277 |
|
266 | 278 | }
|
267 | 279 |
|
| 280 | + public static class ConverterAnnotatedExampleBean { |
| 281 | + |
| 282 | + private final LocalDate date; |
| 283 | + |
| 284 | + ConverterAnnotatedExampleBean(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) { |
| 285 | + this.date = date; |
| 286 | + } |
| 287 | + |
| 288 | + public LocalDate getDate() { |
| 289 | + return this.date; |
| 290 | + } |
| 291 | + |
| 292 | + } |
| 293 | + |
268 | 294 | }
|
0 commit comments