Annotation Interface FilterContent
Declares that a method should be invoked to filter the visibility of an object for a specific
User.
Filtering allows objects to dynamically adjust their exposed content based on who is viewing them. This is especially useful in projections, document models, or search results that may be shared with different roles.
Injection: The annotated method may accept the following parameters:
User– the current user performing the access- Root object – the top-level object being filtered (useful for context when filtering nested values)
Graph<T>– while filtering a model graph, the current model graph or a typed ancestor graph; resolving it reuses the graph that is already being serialized
Return value: The method should return:
this– if the value is fully visible- a modified copy – if only a subset of the value should be shown
null– if the value should be completely hidden
Graph, its root model may instead return an immutable Graph view such as
Graph.filterBranches(java.util.function.Predicate). The view is applied once before individual model values
are filtered, allowing a complete response graph to be selected without copying models or repeatedly traversing
every descendant branch.
Recursive filtering: Filtering is automatically applied to nested objects, collections, and maps.
When filtering results in null for an item inside a collection or map:
- The item is removed from a
List - The key-value pair is removed from a
Map
Example (filtering the object):
public class Order {
@FilterContent
Order filter(User user) {
return user.hasRole("admin") ? this : new Order(maskedFieldsOnly());
}
}
Example (filtering a nested item with root injection):
@FilterContent
public LineItem filter(User user, Order root) {
return root.isPublic() ? this : null;
}
Invocation: Filtering can be applied in two ways:
- Explicitly by calling
Fluxzero.filterContent(Object, User) - Automatically for request handler results when the handler, its class, or package is annotated with
@FilterContent
For automatic filtering: @FilterContent can be applied to a handler at three levels:
- Method level - filters specific method results
- Type level - automatically filters all handler results in the class
- Package level - automatically filters all handler results in the package or subpackage
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanApplies a model graph root's filter to every descendant node as well.
-
Element Details
-
descendants
boolean descendantsApplies a model graph root's filter to every descendant node as well. The method may inject the currentGraphnode and returnGraph.get()to retain it, a replacement value, ornullto remove that node and its branch. A descendant's own content filter is applied afterwards. This setting is unnecessary for a root filter that returns an immutable Graph view.- Default:
false
-