Class JacksonContentFilter.FilteringSerializer

java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<Object>
io.fluxzero.sdk.common.serialization.jackson.JacksonContentFilter.FilteringSerializer
All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
Enclosing class:
JacksonContentFilter

protected static class JacksonContentFilter.FilteringSerializer extends com.fasterxml.jackson.databind.JsonSerializer<Object>
Custom Jackson serializer that attempts to invoke a FilterContent handler method during serialization.

It caches matchers by class and uses HandlerInspector to find the appropriate handler methods.

The serializer behaves gracefully:

  • If the handler returns null and the object is not part of an array, null is written out.
  • If filtering fails, the original object is serialized as a fallback.
The root object (used for matching context) is tracked using a thread-local field rootValue.
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer

    com.fasterxml.jackson.databind.JsonSerializer.None
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final ThreadLocal<Object>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isEmpty(com.fasterxml.jackson.databind.SerializerProvider provider, Object value)
    Determines if the value should be considered empty, based on whether filtering returns null.
    void
    serialize(Object input, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider provider)
     
    void
    serializeAndThen(Object input, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, io.fluxzero.common.ThrowingConsumer<Object> followUp)
    Invokes the content filter if available and serializes the filtered result.
    void
    serializeWithType(Object input, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSerializer)
     

    Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer

    acceptJsonFormatVisitor, getDelegatee, handledType, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • FilteringSerializer

      protected FilteringSerializer()
  • Method Details

    • serialize

      public void serialize(Object input, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider provider)
      Specified by:
      serialize in class com.fasterxml.jackson.databind.JsonSerializer<Object>
    • serializeWithType

      public void serializeWithType(Object input, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSerializer)
      Overrides:
      serializeWithType in class com.fasterxml.jackson.databind.JsonSerializer<Object>
    • serializeAndThen

      public void serializeAndThen(Object input, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, io.fluxzero.common.ThrowingConsumer<Object> followUp)
      Invokes the content filter if available and serializes the filtered result. If filtering fails, it logs a warning and falls back to serializing the original object.
      Parameters:
      input - the object to serialize
      jsonGenerator - the JSON generator
      followUp - logic to continue serialization with the possibly filtered result
    • isEmpty

      public boolean isEmpty(com.fasterxml.jackson.databind.SerializerProvider provider, Object value)
      Determines if the value should be considered empty, based on whether filtering returns null.
      Overrides:
      isEmpty in class com.fasterxml.jackson.databind.JsonSerializer<Object>