Class JacksonContentFilter

java.lang.Object
io.fluxzero.sdk.common.serialization.jackson.JacksonContentFilter
All Implemented Interfaces:
ContentFilter

public class JacksonContentFilter extends Object implements 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.FilteringSerializer is registered with Jackson using a BeanSerializerModifier.
  • The serializer tries to invoke a FilterContent-annotated method using the HandlerInspector and passes in the root object and current User (via parameter resolvers).
  • If filtering returns a different value, that value is serialized instead.
See Also:
  • Constructor Details

    • JacksonContentFilter

      public JacksonContentFilter(com.fasterxml.jackson.databind.ObjectMapper mapper)
      Creates a new content filter using the provided ObjectMapper.

      The mapper will be configured with:

      Parameters:
      mapper - an ObjectMapper used for filtering and serialization
  • Method Details

    • filterContent

      public <T> T filterContent(T value, User viewer)
      Description copied from interface: ContentFilter
      Filters the given value based on the current viewer (user) context. If a FilterContent handler exists in the object's class, it will be invoked to produce a user-specific view of the data.
      Specified by:
      filterContent in interface ContentFilter
      Type Parameters:
      T - the type of the content object
      Parameters:
      value - the original object
      viewer - the user viewing the content
      Returns:
      the filtered version of the object, or the original object if filtering failed or was not applicable