An implementation of the BeanIntrospector
interface which can detect write methods for properties used in fluent API scenario.
A fluent API allows setting multiple properties using a single statement by supporting so-called method chaining: Methods for setting a property value do not return void, but an object which can be called for setting another property. An example of such a fluent API could look as follows:
public class FooBuilder { public FooBuilder setFooProperty1(String value) { ... return this; } public FooBuilder setFooProperty2(int value) { ... return this; } }Per default,
PropertyUtils
does not detect methods like this because, having a non-void return type, they violate the Java Beans specification. This class is more tolerant with regards to the return type of a set method. It basically iterates over all methods of a class and filters them for a configurable prefix (the default prefix is set
). It then generates corresponding PropertyDescriptor
objects for the methods found which use these methods as write methods.
An instance of this class is intended to collaborate with a {@link DefaultBeanIntrospector} object. So best results are achieved byadding this instance as custom {@code BeanIntrospector} after theDefaultBeanIntrospector
object. Then default introspection finds read-only properties because it does not detect the write methods with a non-void return type. {@code FluentPropertyBeanIntrospector}completes the descriptors for these properties by setting the correct write method.
|
|
|
|
|
|