/
ValueObjectBinderTests.java
852 lines (657 loc) · 24.6 KB
/
ValueObjectBinderTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
/*
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.context.properties.bind;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.io.TempDir;
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.boot.testsupport.compiler.TestCompiler;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.Assert;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests for {@link ValueObjectBinder}.
*
* @author Madhura Bhave
* @author Phillip Webb
*/
class ValueObjectBinderTests {
private final List<ConfigurationPropertySource> sources = new ArrayList<>();
private final Binder binder = new Binder(this.sources);
@Test
void bindToClassShouldCreateBoundBean() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
source.put("foo.long-value", "34");
source.put("foo.boolean-value", "true");
source.put("foo.string-value", "foo");
source.put("foo.enum-value", "foo-bar");
this.sources.add(source);
ExampleValueBean bean = this.binder.bind("foo", Bindable.of(ExampleValueBean.class)).get();
assertThat(bean.getIntValue()).isEqualTo(12);
assertThat(bean.getLongValue()).isEqualTo(34);
assertThat(bean.isBooleanValue()).isTrue();
assertThat(bean.getStringValue()).isEqualTo("foo");
assertThat(bean.getEnumValue()).isEqualTo(ExampleEnum.FOO_BAR);
}
@Test
void bindToClassWhenHasNoPrefixShouldCreateBoundBean() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("int-value", "12");
source.put("long-value", "34");
source.put("boolean-value", "true");
source.put("string-value", "foo");
source.put("enum-value", "foo-bar");
this.sources.add(source);
ExampleValueBean bean = this.binder.bind(ConfigurationPropertyName.of(""), Bindable.of(ExampleValueBean.class))
.get();
assertThat(bean.getIntValue()).isEqualTo(12);
assertThat(bean.getLongValue()).isEqualTo(34);
assertThat(bean.isBooleanValue()).isTrue();
assertThat(bean.getStringValue()).isEqualTo("foo");
assertThat(bean.getEnumValue()).isEqualTo(ExampleEnum.FOO_BAR);
}
@Test
void bindToAbstractClassWithShouldNotBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.name", "test");
this.sources.add(source);
boolean bound = this.binder.bind("foo", Bindable.of(ExampleAbstractBean.class)).isBound();
assertThat(bound).isFalse();
}
@Test
void bindToClassWithMultipleConstructorsShouldNotBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
this.sources.add(source);
boolean bound = this.binder.bind("foo", Bindable.of(MultipleConstructorsBean.class)).isBound();
assertThat(bound).isFalse();
}
@Test
void bindToClassWithMultipleConstructorsAndFilterShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
this.sources.add(source);
Constructor<?>[] constructors = MultipleConstructorsBean.class.getDeclaredConstructors();
Constructor<?> constructor = (constructors[0].getParameterCount() == 1) ? constructors[0] : constructors[1];
Binder binder = new Binder(this.sources, null, (ConversionService) null, null, null,
(bindable, isNestedConstructorBinding) -> constructor);
MultipleConstructorsBean bound = binder.bind("foo", Bindable.of(MultipleConstructorsBean.class)).get();
assertThat(bound.getIntValue()).isEqualTo(12);
}
@Test
void bindToClassWithOnlyDefaultConstructorShouldNotBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
this.sources.add(source);
boolean bound = this.binder.bind("foo", Bindable.of(DefaultConstructorBean.class)).isBound();
assertThat(bound).isFalse();
}
@Test
void bindToClassWithMultipleConstructorsWhenOnlyOneIsNotPrivateShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
this.sources.add(source);
MultipleConstructorsOnlyOneNotPrivateBean bean = this.binder
.bind("foo", Bindable.of(MultipleConstructorsOnlyOneNotPrivateBean.class)).get();
bean = bean.withString("test");
assertThat(bean.getIntValue()).isEqualTo(12);
assertThat(bean.getStringValue()).isEqualTo("test");
}
@Test
void bindToClassShouldBindNested() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value-bean.int-value", "123");
source.put("foo.value-bean.long-value", "34");
source.put("foo.value-bean.string-value", "foo");
this.sources.add(source);
ExampleNestedBean bean = this.binder.bind("foo", Bindable.of(ExampleNestedBean.class)).get();
assertThat(bean.getValueBean().getIntValue()).isEqualTo(123);
assertThat(bean.getValueBean().getLongValue()).isEqualTo(34);
assertThat(bean.getValueBean().isBooleanValue()).isFalse();
assertThat(bean.getValueBean().getStringValue()).isEqualTo("foo");
assertThat(bean.getValueBean().getEnumValue()).isNull();
}
@Test
void bindToClassWithNoValueForPrimitiveShouldUseDefault() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.string-value", "foo");
this.sources.add(source);
ExampleValueBean bean = this.binder.bind("foo", Bindable.of(ExampleValueBean.class)).get();
assertThat(bean.getIntValue()).isEqualTo(0);
assertThat(bean.getLongValue()).isEqualTo(0);
assertThat(bean.isBooleanValue()).isEqualTo(false);
assertThat(bean.getStringValue()).isEqualTo("foo");
}
@Test
void bindToClassWithNoValueAndDefaultValueShouldNotBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.string-value", "foo");
this.sources.add(source);
assertThat(this.binder.bind("foo", Bindable.of(ExampleDefaultValueBean.class)).isBound()).isFalse();
}
@Test
void bindToClassWhenNoParameterBoundShouldReturnNull() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
this.sources.add(source.nonIterable());
BindResult<ExampleFailingConstructorBean> result = this.binder.bind("foo",
Bindable.of(ExampleFailingConstructorBean.class));
assertThat(result.isBound()).isFalse();
}
@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");
}
@Test
void bindWithAnnotationsAndDefaultValue() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar", "hello");
this.sources.add(source);
ConverterAnnotatedExampleBean bean = this.binder.bind("foo", Bindable.of(ConverterAnnotatedExampleBean.class))
.get();
assertThat(bean.getDate().toString()).isEqualTo("2019-05-10");
}
@Test
void bindToClassWhenHasPackagePrivateConstructorShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.property", "test");
this.sources.add(source);
ExamplePackagePrivateConstructorBean bound = this.binder
.bind("foo", Bindable.of(ExamplePackagePrivateConstructorBean.class)).get();
assertThat(bound.getProperty()).isEqualTo("test");
}
@Test
void createShouldReturnCreatedValue() {
ExampleValueBean value = this.binder.bindOrCreate("foo", Bindable.of(ExampleValueBean.class));
assertThat(value.getIntValue()).isEqualTo(0);
assertThat(value.getLongValue()).isEqualTo(0);
assertThat(value.isBooleanValue()).isEqualTo(false);
assertThat(value.getStringValue()).isNull();
assertThat(value.getEnumValue()).isNull();
}
@Test
void createWithNestedShouldReturnCreatedValue() {
ExampleNestedBean value = this.binder.bindOrCreate("foo", Bindable.of(ExampleNestedBean.class));
assertThat(value.getValueBean()).isEqualTo(null);
}
@Test
void createWithDefaultValuesShouldReturnCreatedWithDefaultValues() {
ExampleDefaultValueBean value = this.binder.bindOrCreate("foo", Bindable.of(ExampleDefaultValueBean.class));
assertThat(value.getIntValue()).isEqualTo(5);
assertThat(value.getStringsList()).containsOnly("a", "b", "c");
assertThat(value.getCustomList()).containsOnly("x,y,z");
}
@Test
void createWithDefaultValuesAndAnnotationsShouldReturnCreatedWithDefaultValues() {
ConverterAnnotatedExampleBean bean = this.binder.bindOrCreate("foo",
Bindable.of(ConverterAnnotatedExampleBean.class));
assertThat(bean.getDate().toString()).isEqualTo("2019-05-10");
}
@Test
void bindWhenAllPropertiesBoundShouldClearConfigurationProperty() { // gh-18704
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar", "hello");
this.sources.add(source);
Bindable<ValidatingConstructorBean> target = Bindable.of(ValidatingConstructorBean.class);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", target))
.satisfies(this::noConfigurationProperty);
}
@Test
void bindToClassShouldBindWithGenerics() {
// gh-19156
ResolvableType type = ResolvableType.forClassWithGenerics(Map.class, String.class, String.class);
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value.bar", "baz");
this.sources.add(source);
GenericValue<Map<String, String>> bean = this.binder.bind("foo", Bindable
.<GenericValue<Map<String, String>>>of(ResolvableType.forClassWithGenerics(GenericValue.class, type)))
.get();
assertThat(bean.getValue().get("bar")).isEqualTo("baz");
}
@Test
void bindWhenParametersWithDefaultValueShouldReturnNonNullValues() {
NestedConstructorBeanWithDefaultValue bound = this.binder.bindOrCreate("foo",
Bindable.of(NestedConstructorBeanWithDefaultValue.class));
assertThat(bound.getNestedImmutable().getFoo()).isEqualTo("hello");
assertThat(bound.getNestedJavaBean()).isNotNull();
}
@Test
void bindWhenJavaLangParameterWithEmptyDefaultValueShouldThrowException() {
assertThatExceptionOfType(BindException.class)
.isThrownBy(() -> this.binder.bindOrCreate("foo",
Bindable.of(NestedConstructorBeanWithEmptyDefaultValueForJavaLangTypes.class)))
.withStackTraceContaining("Parameter of type java.lang.String must have a non-empty default value.");
}
@Test
void bindWhenCollectionParameterWithEmptyDefaultValueShouldReturnEmptyInstance() {
NestedConstructorBeanWithEmptyDefaultValueForCollectionTypes bound = this.binder.bindOrCreate("foo",
Bindable.of(NestedConstructorBeanWithEmptyDefaultValueForCollectionTypes.class));
assertThat(bound.getListValue()).isEmpty();
}
@Test
void bindWhenMapParametersWithEmptyDefaultValueShouldReturnEmptyInstance() {
NestedConstructorBeanWithEmptyDefaultValueForMapTypes bound = this.binder.bindOrCreate("foo",
Bindable.of(NestedConstructorBeanWithEmptyDefaultValueForMapTypes.class));
assertThat(bound.getMapValue()).isEmpty();
}
@Test
void bindWhenArrayParameterWithEmptyDefaultValueShouldReturnEmptyInstance() {
NestedConstructorBeanWithEmptyDefaultValueForArrayTypes bound = this.binder.bindOrCreate("foo",
Bindable.of(NestedConstructorBeanWithEmptyDefaultValueForArrayTypes.class));
assertThat(bound.getArrayValue()).isEmpty();
}
@Test
void bindWhenOptionalParameterWithEmptyDefaultValueShouldReturnEmptyInstance() {
NestedConstructorBeanWithEmptyDefaultValueForOptionalTypes bound = this.binder.bindOrCreate("foo",
Bindable.of(NestedConstructorBeanWithEmptyDefaultValueForOptionalTypes.class));
assertThat(bound.getOptionalValue()).isEmpty();
}
@Test
void bindWhenEnumParameterWithEmptyDefaultValueShouldThrowException() {
assertThatExceptionOfType(BindException.class)
.isThrownBy(() -> this.binder.bindOrCreate("foo",
Bindable.of(NestedConstructorBeanWithEmptyDefaultValueForEnumTypes.class)))
.withStackTraceContaining(
"Parameter of type org.springframework.boot.context.properties.bind.ValueObjectBinderTests$NestedConstructorBeanWithEmptyDefaultValueForEnumTypes$Foo must have a non-empty default value.");
}
@Test
void bindWhenPrimitiveParameterWithEmptyDefaultValueShouldThrowException() {
assertThatExceptionOfType(BindException.class)
.isThrownBy(() -> this.binder.bindOrCreate("foo",
Bindable.of(NestedConstructorBeanWithEmptyDefaultValueForPrimitiveTypes.class)))
.withStackTraceContaining("Parameter of type int must have a non-empty default value.");
}
@Test
void bindWhenBindingToPathTypeWithValue() { // gh-21263
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("test.name", "test");
source.put("test.path", "specific_value");
this.sources.add(source);
Bindable<PathBean> target = Bindable.of(PathBean.class);
PathBean bound = this.binder.bind("test", target).get();
assertThat(bound.getName()).isEqualTo("test");
assertThat(bound.getPath()).isEqualTo(Paths.get("specific_value"));
}
@Test
void bindWhenBindingToPathTypeWithDefaultValue() { // gh-21263
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("test.name", "test");
this.sources.add(source);
Bindable<PathBean> target = Bindable.of(PathBean.class);
PathBean bound = this.binder.bindOrCreate("test", target);
assertThat(bound.getName()).isEqualTo("test");
assertThat(bound.getPath()).isEqualTo(Paths.get("default_value"));
}
@Test
void bindToAnnotationNamedParameter() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("test.import", "test");
this.sources.add(source);
Bindable<NamedParameter> target = Bindable.of(NamedParameter.class);
NamedParameter bound = this.binder.bindOrCreate("test", target);
assertThat(bound.getImportName()).isEqualTo("test");
}
@Test
@EnabledForJreRange(min = JRE.JAVA_16)
void bindToRecordWithDefaultValue(@TempDir File tempDir) throws IOException, ClassNotFoundException {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("test.record.property1", "value-from-config-1");
this.sources.add(source);
File recordProperties = new File(tempDir, "RecordProperties.java");
try (PrintWriter writer = new PrintWriter(new FileWriter(recordProperties))) {
writer.println("public record RecordProperties(");
writer.println(
"@org.springframework.boot.context.properties.bind.DefaultValue(\"default-value-1\") String property1,");
writer.println(
"@org.springframework.boot.context.properties.bind.DefaultValue(\"default-value-2\") String property2");
writer.println(") {");
writer.println("}");
}
TestCompiler compiler = new TestCompiler(tempDir);
compiler.getTask(Arrays.asList(recordProperties)).call();
ClassLoader ucl = new URLClassLoader(new URL[] { tempDir.toURI().toURL() });
Object bean = this.binder.bind("test.record", Class.forName("RecordProperties", true, ucl)).get();
assertThat(bean).hasFieldOrPropertyWithValue("property1", "value-from-config-1")
.hasFieldOrPropertyWithValue("property2", "default-value-2");
}
private void noConfigurationProperty(BindException ex) {
assertThat(ex.getProperty()).isNull();
}
static class ExampleValueBean {
private final int intValue;
private final long longValue;
private final boolean booleanValue;
private final String stringValue;
private final ExampleEnum enumValue;
ExampleValueBean(int intValue, long longValue, boolean booleanValue, String stringValue,
ExampleEnum enumValue) {
this.intValue = intValue;
this.longValue = longValue;
this.booleanValue = booleanValue;
this.stringValue = stringValue;
this.enumValue = enumValue;
}
int getIntValue() {
return this.intValue;
}
long getLongValue() {
return this.longValue;
}
boolean isBooleanValue() {
return this.booleanValue;
}
String getStringValue() {
return this.stringValue;
}
ExampleEnum getEnumValue() {
return this.enumValue;
}
}
public enum ExampleEnum {
FOO_BAR,
BAR_BAZ
}
static class MultipleConstructorsBean {
private final int intValue;
MultipleConstructorsBean(int intValue) {
this(intValue, 23L, "hello");
}
MultipleConstructorsBean(int intValue, long longValue, String stringValue) {
this.intValue = intValue;
}
int getIntValue() {
return this.intValue;
}
}
static class MultipleConstructorsOnlyOneNotPrivateBean {
private final int intValue;
private final String stringValue;
MultipleConstructorsOnlyOneNotPrivateBean(int intValue) {
this(intValue, 23L, "hello");
}
private MultipleConstructorsOnlyOneNotPrivateBean(int intValue, long longValue, String stringValue) {
this.intValue = intValue;
this.stringValue = stringValue;
}
int getIntValue() {
return this.intValue;
}
String getStringValue() {
return this.stringValue;
}
MultipleConstructorsOnlyOneNotPrivateBean withString(String stringValue) {
return new MultipleConstructorsOnlyOneNotPrivateBean(this.intValue, 0, stringValue);
}
}
abstract static class ExampleAbstractBean {
private final String name;
ExampleAbstractBean(String name) {
this.name = name;
}
String getName() {
return this.name;
}
}
static class DefaultConstructorBean {
DefaultConstructorBean() {
}
}
static class ExampleNestedBean {
private final ExampleValueBean valueBean;
ExampleNestedBean(ExampleValueBean valueBean) {
this.valueBean = valueBean;
}
ExampleValueBean getValueBean() {
return this.valueBean;
}
}
static class ExampleDefaultValueBean {
private final int intValue;
private final List<String> stringsList;
private final List<String> customList;
ExampleDefaultValueBean(@DefaultValue("5") int intValue,
@DefaultValue({ "a", "b", "c" }) List<String> stringsList,
@DefaultValue("x,y,z") List<String> customList) {
this.intValue = intValue;
this.stringsList = stringsList;
this.customList = customList;
}
int getIntValue() {
return this.intValue;
}
List<String> getStringsList() {
return this.stringsList;
}
List<String> getCustomList() {
return this.customList;
}
}
static class ExampleFailingConstructorBean {
private final String name;
private final Object value;
ExampleFailingConstructorBean(String name, String value) {
Objects.requireNonNull(name, "'name' must be not null.");
Objects.requireNonNull(value, "'value' must be not null.");
this.name = name;
this.value = value;
}
String getName() {
return this.name;
}
Object getValue() {
return this.value;
}
}
static class ConverterAnnotatedExampleBean {
private final LocalDate date;
private final String bar;
ConverterAnnotatedExampleBean(
@DefaultValue("2019-05-10") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date, String bar) {
this.date = date;
this.bar = bar;
}
LocalDate getDate() {
return this.date;
}
String getBar() {
return this.bar;
}
}
static class ExamplePackagePrivateConstructorBean {
private final String property;
ExamplePackagePrivateConstructorBean(String property) {
this.property = property;
}
String getProperty() {
return this.property;
}
}
static class ValidatingConstructorBean {
private final String foo;
private final String bar;
ValidatingConstructorBean(String foo, String bar) {
Assert.notNull(foo, "Foo must not be null");
this.foo = foo;
this.bar = bar;
}
String getFoo() {
return this.foo;
}
String getBar() {
return this.bar;
}
}
static class GenericValue<T> {
private final T value;
GenericValue(T value) {
this.value = value;
}
T getValue() {
return this.value;
}
}
static class NestedConstructorBeanWithDefaultValue {
private final NestedImmutable nestedImmutable;
private final NestedJavaBean nestedJavaBean;
NestedConstructorBeanWithDefaultValue(@DefaultValue NestedImmutable nestedImmutable,
@DefaultValue NestedJavaBean nestedJavaBean) {
this.nestedImmutable = nestedImmutable;
this.nestedJavaBean = nestedJavaBean;
}
NestedImmutable getNestedImmutable() {
return this.nestedImmutable;
}
NestedJavaBean getNestedJavaBean() {
return this.nestedJavaBean;
}
}
static class NestedImmutable {
private final String foo;
private final String bar;
NestedImmutable(@DefaultValue("hello") String foo, String bar) {
this.foo = foo;
this.bar = bar;
}
String getFoo() {
return this.foo;
}
String getBar() {
return this.bar;
}
}
static class NestedJavaBean {
private String value;
String getValue() {
return this.value;
}
}
static class NestedConstructorBeanWithEmptyDefaultValueForJavaLangTypes {
private final String stringValue;
NestedConstructorBeanWithEmptyDefaultValueForJavaLangTypes(@DefaultValue String stringValue) {
this.stringValue = stringValue;
}
String getStringValue() {
return this.stringValue;
}
}
static class NestedConstructorBeanWithEmptyDefaultValueForCollectionTypes {
private final List<String> listValue;
NestedConstructorBeanWithEmptyDefaultValueForCollectionTypes(@DefaultValue List<String> listValue) {
this.listValue = listValue;
}
List<String> getListValue() {
return this.listValue;
}
}
static class NestedConstructorBeanWithEmptyDefaultValueForMapTypes {
private final Map<String, String> mapValue;
NestedConstructorBeanWithEmptyDefaultValueForMapTypes(@DefaultValue Map<String, String> mapValue) {
this.mapValue = mapValue;
}
Map<String, String> getMapValue() {
return this.mapValue;
}
}
static class NestedConstructorBeanWithEmptyDefaultValueForArrayTypes {
private final String[] arrayValue;
NestedConstructorBeanWithEmptyDefaultValueForArrayTypes(@DefaultValue String[] arrayValue) {
this.arrayValue = arrayValue;
}
String[] getArrayValue() {
return this.arrayValue;
}
}
static class NestedConstructorBeanWithEmptyDefaultValueForOptionalTypes {
private final Optional<String> optionalValue;
NestedConstructorBeanWithEmptyDefaultValueForOptionalTypes(@DefaultValue Optional<String> optionalValue) {
this.optionalValue = optionalValue;
}
Optional<String> getOptionalValue() {
return this.optionalValue;
}
}
static class NestedConstructorBeanWithEmptyDefaultValueForEnumTypes {
private Foo foo;
NestedConstructorBeanWithEmptyDefaultValueForEnumTypes(@DefaultValue Foo foo) {
this.foo = foo;
}
Foo getFoo() {
return this.foo;
}
enum Foo {
BAR, BAZ
}
}
static class NestedConstructorBeanWithEmptyDefaultValueForPrimitiveTypes {
private int intValue;
NestedConstructorBeanWithEmptyDefaultValueForPrimitiveTypes(@DefaultValue int intValue) {
this.intValue = intValue;
}
int getIntValue() {
return this.intValue;
}
}
static class PathBean {
private final String name;
private final Path path;
PathBean(String name, @DefaultValue("default_value") Path path) {
this.name = name;
this.path = path;
}
String getName() {
return this.name;
}
Path getPath() {
return this.path;
}
}
static class NamedParameter {
private final String importName;
NamedParameter(@Name("import") String importName) {
this.importName = importName;
}
String getImportName() {
return this.importName;
}
}
}