51
51
import org .springframework .boot .actuate .endpoint .annotation .ReadOperation ;
52
52
import org .springframework .boot .context .properties .ConfigurationProperties ;
53
53
import org .springframework .boot .context .properties .ConfigurationPropertiesBean ;
54
+ import org .springframework .boot .context .properties .ConstructorBinding ;
54
55
import org .springframework .context .ApplicationContext ;
55
56
import org .springframework .context .ApplicationContextAware ;
56
57
import org .springframework .util .ClassUtils ;
69
70
* @author Christian Dupuis
70
71
* @author Dave Syer
71
72
* @author Stephane Nicoll
73
+ * @author Leo Li
72
74
* @since 2.0.0
73
75
*/
74
76
@ Endpoint (id = "configprops" )
@@ -312,6 +314,13 @@ public List<BeanPropertyWriter> changeProperties(SerializationConfig config, Bea
312
314
}
313
315
314
316
private boolean isReadable (BeanDescription beanDesc , BeanPropertyWriter writer ) {
317
+ // if the class has the @ConstructorBinding annotation or
318
+ // one constructor of this class has the @ConstructorBinding annotation,
319
+ // we can ignore the setter method.
320
+ if (beanDesc .getClassAnnotations ().has (ConstructorBinding .class )
321
+ || isConstructorsContainConstructorBinding (beanDesc )) {
322
+ return true ;
323
+ }
315
324
Class <?> parentType = beanDesc .getType ().getRawClass ();
316
325
Class <?> type = writer .getType ().getRawClass ();
317
326
AnnotatedMethod setter = findSetter (beanDesc , writer );
@@ -325,6 +334,11 @@ private boolean isReadable(BeanDescription beanDesc, BeanPropertyWriter writer)
325
334
|| Map .class .isAssignableFrom (type ) || Collection .class .isAssignableFrom (type );
326
335
}
327
336
337
+ private boolean isConstructorsContainConstructorBinding (BeanDescription beanDesc ) {
338
+ return beanDesc .getConstructors ().stream ()
339
+ .anyMatch ((annotatedConstructor ) -> annotatedConstructor .hasAnnotation (ConstructorBinding .class ));
340
+ }
341
+
328
342
private AnnotatedMethod findSetter (BeanDescription beanDesc , BeanPropertyWriter writer ) {
329
343
String name = "set" + determineAccessorSuffix (writer .getName ());
330
344
Class <?> type = writer .getType ().getRawClass ();
0 commit comments