Class SimpleBeanPropertyFilter

java.lang.Object
tools.jackson.databind.ser.std.SimpleBeanPropertyFilter
All Implemented Interfaces:
Snapshottable<PropertyFilter>, PropertyFilter
Direct Known Subclasses:
SimpleBeanPropertyFilter.FilterExceptFilter, SimpleBeanPropertyFilter.SerializeExceptFilter

public class SimpleBeanPropertyFilter extends Object implements PropertyFilter
Simple PropertyFilter implementation that only uses property name to determine whether to serialize property as is, or to filter it out.

Use of this class as the base implementation for any custom PropertyFilter implementations is strongly encouraged, because it can provide default implementation for any methods that may be added in PropertyFilter (as unfortunate as additions may be).

  • Constructor Details

    • SimpleBeanPropertyFilter

      protected SimpleBeanPropertyFilter()
  • Method Details

    • snapshot

      public PropertyFilter snapshot()
      Specified by:
      snapshot in interface Snapshottable<PropertyFilter>
    • serializeAll

      public static SimpleBeanPropertyFilter serializeAll()
      Convenience factory method that will return a "no-op" filter that will simply just serialize all properties that are given, and filter out nothing.
    • filterOutAll

      public static SimpleBeanPropertyFilter filterOutAll()
      Convenience factory method that will return a filter that will simply filter out everything.
    • filterOutAllExcept

      public static SimpleBeanPropertyFilter filterOutAllExcept(Set<String> properties)
      Factory method to construct filter that filters out all properties except ones includes in set
    • filterOutAllExcept

      public static SimpleBeanPropertyFilter filterOutAllExcept(String... propertyArray)
    • serializeAllExcept

      public static SimpleBeanPropertyFilter serializeAllExcept(Set<String> properties)
    • serializeAllExcept

      public static SimpleBeanPropertyFilter serializeAllExcept(String... propertyArray)
    • include

      protected boolean include(BeanPropertyWriter writer)
      Method called to determine whether property will be included (if 'true' returned) or filtered out (if 'false' returned)
    • include

      protected boolean include(PropertyWriter writer)
      Method called to determine whether property will be included (if 'true' returned) or filtered out (if 'false' returned)
    • includeElement

      protected boolean includeElement(Object elementValue)
      Method that defines what to do with container elements (values contained in an array or Collection: default implementation simply writes them out.
    • serializeAsProperty

      public void serializeAsProperty(Object pojo, JsonGenerator g, SerializationContext provider, PropertyWriter writer) throws Exception
      Description copied from interface: PropertyFilter
      Method called by BeanSerializer to let the filter decide what to do with given bean property value: the usual choices are to either filter out (i.e. do nothing) or write using given PropertyWriter, although filters can choose other to do something different altogether.

      Typical implementation is something like:

       if (include(writer)) {
            writer.serializeAsProperty(pojo, gen, prov);
       }
      
      Specified by:
      serializeAsProperty in interface PropertyFilter
      Parameters:
      pojo - Object that contains property value to serialize
      g - Generator use for serializing value
      provider - Provider that can be used for accessing dynamic aspects of serialization processing
      writer - Object called to do actual serialization of the field, if not filtered out
      Throws:
      Exception
    • serializeAsElement

      public void serializeAsElement(Object elementValue, JsonGenerator g, SerializationContext provider, PropertyWriter writer) throws Exception
      Description copied from interface: PropertyFilter
      Method called by container to let the filter decide what to do with given element value: the usual choices are to either filter out (i.e. do nothing) or write using given PropertyWriter, although filters can choose other to do something different altogether.

      Typical implementation is something like:

       if (include(writer)) {
            writer.serializeAsElement(pojo, gen, prov);
       }
      
      Specified by:
      serializeAsElement in interface PropertyFilter
      Parameters:
      elementValue - Element value being serializerd
      g - Generator use for serializing value
      provider - Provider that can be used for accessing dynamic aspects of serialization processing
      writer - Object called to do actual serialization of the field, if not filtered out
      Throws:
      Exception
    • depositSchemaProperty

      public void depositSchemaProperty(PropertyWriter writer, JsonObjectFormatVisitor objectVisitor, SerializationContext provider)
      Description copied from interface: PropertyFilter
      Method called by BeanSerializer to let the filter determine whether, and in what form the given property exist within the parent, or root, schema. Filters can omit adding the property to the node, or choose the form of the schema value for the property

      Typical implementation is something like:

       if (include(writer)) {
            writer.depositSchemaProperty(objectVisitor, provider);
       }
      
      Specified by:
      depositSchemaProperty in interface PropertyFilter
      Parameters:
      writer - Bean property serializer to use to create schema value
      objectVisitor - JsonObjectFormatVisitor which should be aware of the property's existence
      provider - Serialization context