Class JacksonContentFilter
java.lang.Object
io.fluxzero.sdk.common.serialization.jackson.JacksonContentFilter
- All Implemented Interfaces:
ContentFilter
A
ContentFilter implementation that uses Jackson to filter content dynamically for a specific User.
This class enables context-aware filtering based on FilterContent annotated handler methods in the value’s
class. These handlers can compute and return a filtered version of an object based on the current user context.
Filtering is performed via Jackson serialization, where a custom serializer is installed to intercept object serialization and invoke the appropriate content filtering logic.
How it works
- A
JacksonContentFilter.FilteringSerializeris registered with Jackson using aBeanSerializerModifier. - The serializer tries to invoke a
FilterContent-annotated method using theHandlerInspectorand passes in the root object and currentUser(via parameter resolvers). - If filtering returns a different value, that value is serialized instead.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classCustom Jackson serializer that attempts to invoke aFilterContenthandler method during serialization. -
Constructor Summary
ConstructorsConstructorDescriptionJacksonContentFilter(com.fasterxml.jackson.databind.ObjectMapper mapper) Creates a new content filter using the providedObjectMapper. -
Method Summary
Modifier and TypeMethodDescription<T> TfilterContent(T value, User viewer) Filters the given value based on the current viewer (user) context.
-
Constructor Details
-
JacksonContentFilter
public JacksonContentFilter(com.fasterxml.jackson.databind.ObjectMapper mapper) Creates a new content filter using the providedObjectMapper.The provided mapper is kept unchanged. A single internal copy is configured with:
- ALWAYS inclusion policy (to serialize nulls)
- A
JacksonContentFilter.FilteringSerializerfor applyingFilterContentannotations - Disabled
JsonIgnorehandling, to ensure all fields are considered for filtering
- Parameters:
mapper- an ObjectMapper used for filtering and serialization
-
-
Method Details
-
filterContent
Description copied from interface:ContentFilterFilters the given value based on the current viewer (user) context. If aFilterContenthandler exists in the object's class, it will be invoked to produce a user-specific view of the data.- Specified by:
filterContentin interfaceContentFilter- Type Parameters:
T- the type of the content object- Parameters:
value- the original objectviewer- the user viewing the content- Returns:
- the filtered version of the object, or the original object if filtering failed or was not applicable
-