Interface Filters
Occasionally, you may want to limit bean properties to only those defined on a parent class or interface. This is accomplished through interface filters.
Interface filters are defined through the following:
For example, let's define the following interface and implementation:
Suppose we only want to render the properties defined on our interface, not the implementation. To do so, we can define the following bean filter:
When serialized, the serialized bean will only include properties defined on the interface.
WriterSerializer s = JsonSerializer
.
The {@link oaj.BeanContextBuilder#beanFilters(Object...)} method will automatically interpret any
non-BeanFilter
classes passed in as meaning interface classes.
So in the previous example, the BeanFilter
class could have been avoided altogether by just
passing in MyInterface.
to the serializer, like so:
WriterSerializer s = JsonSerializer
.
The annotation equivalent is {@link oaj.annotation.Bean#interfaceClass() Bean#interfaceClass()}.
The annotation can be used in a couple of ways.
Using the annotation on an interface will be inherited by all children.
The annotation can be used on parent classes as well. Child beans will only serialize properties defined on the parent class.