Class BeanInterceptor<T>
- Type Parameters:
T
- The bean type.
- Direct Known Subclasses:
BeanInterceptor.Void
Bean interceptors intercept calls to bean getters and setters to allow them to override values in transit.
Example:
Bean interceptors are registered in the following way:
Example:
See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Non-existent bean interceptor. -
Field Summary
Modifier and TypeFieldDescriptionstatic final BeanInterceptor<Object>
Default reusable property filter instance. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionreadProperty
(T bean, String name, Object value) Property read interceptor.writeProperty
(T bean, String name, Object value) Property write interceptor.
-
Field Details
-
DEFAULT
Default reusable property filter instance.
-
-
Constructor Details
-
BeanInterceptor
public BeanInterceptor()
-
-
Method Details
-
readProperty
Property read interceptor.Subclasses can override this property to convert property values to some other object just before serialization.
Example:
// Address filter that strips out sensitive information. public class AddressInterceptorextends BeanInterceptor<Address> {public Object readProperty(Addressbean , Stringname , Objectvalue ) {if ("taxInfo" .equals(name ))return "redacted" ;return value ; } }- Parameters:
bean
- The bean from which the property was read.name
- The property name.value
- The value just extracted from calling the bean getter.- Returns:
- The value to serialize. Default is just to return the existing value.
-
writeProperty
Property write interceptor.Subclasses can override this property to convert property values to some other object just before calling the bean setter.
Example:
// Address filter that strips out sensitive information. public class AddressInterceptorextends BeanInterceptor<Address> {public Object writeProperty(Addressbean , Stringname , Objectvalue ) {if ("taxInfo" .equals(name ) &&"redacted" .equals(value ))return TaxInfoUtils.lookup (bean .getStreet(),bean .getCity(),bean .getState());return value ; } }- Parameters:
bean
- The bean from which the property was read.name
- The property name.value
- The value just parsed.- Returns:
- The value to serialize. Default is just to return the existing value.
-