Class PropertyMaskingSafePropertyWriter

java.lang.Object
com.fasterxml.jackson.databind.introspect.ConcreteBeanPropertyBase
com.fasterxml.jackson.databind.ser.PropertyWriter
com.fasterxml.jackson.databind.ser.BeanPropertyWriter
org.kiwiproject.json.PropertyMaskingSafePropertyWriter
All Implemented Interfaces:
com.fasterxml.jackson.databind.BeanProperty, com.fasterxml.jackson.databind.util.Named, Serializable

public class PropertyMaskingSafePropertyWriter extends com.fasterxml.jackson.databind.ser.BeanPropertyWriter
Writes properties "safely" and masks sensitive properties such as passwords. This property writer will attempt to write out the value, but if an exception is thrown, it will instead write a pre-configured value in place of the actual value.

This writer also allows masking (hiding the true value) of certain fields based on their name by writing out asterisks instead of the true value.

NOTE: Generally masking should be used only on String fields, because otherwise the type in the resulting JSON will be different from the source type. For example, if a class has a "secretNumber" of type "int" and it is masked, the resulting JSON contains a String instead of an int, which will likely cause problems if a downstream system reads the JSON expecting an int. For such cases, consider using JsonView instead.

Note that jackson-core and jackson-databind must be available at runtime.

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.BeanProperty

    com.fasterxml.jackson.databind.BeanProperty.Bogus, com.fasterxml.jackson.databind.BeanProperty.Std
  • Field Summary

    Fields inherited from class com.fasterxml.jackson.databind.ser.BeanPropertyWriter

    _accessorMethod, _cfgSerializationType, _contextAnnotations, _declaredType, _dynamicSerializers, _field, _includeInViews, _internalSettings, _member, _name, _nonTrivialBaseType, _nullSerializer, _serializer, _suppressableValue, _suppressNulls, _typeSerializer, _wrapperName, MARKER_FOR_EMPTY

    Fields inherited from class com.fasterxml.jackson.databind.introspect.ConcreteBeanPropertyBase

    _aliases, _metadata

    Fields inherited from interface com.fasterxml.jackson.databind.BeanProperty

    EMPTY_FORMAT, EMPTY_INCLUDE
  • Constructor Summary

    Constructors
    Constructor
    Description
    PropertyMaskingSafePropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter base, List<String> maskedFieldRegexps)
    Construct new instance wrapping the given BeanPropertyWriter using the given list of (String) regular expressions that define the properties which should be masked.
    PropertyMaskingSafePropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter base, PropertyMaskingOptions options)
    Construct new instance wrapping the given BeanPropertyWriter using the given PropertyMaskingOptions to define properties to be masked, as well as replacement text for masked fields and serialization errors.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    serializeAsField(Object bean, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider prov)
     

    Methods inherited from class com.fasterxml.jackson.databind.ser.BeanPropertyWriter

    _depositSchemaProperty, _findAndAddDynamic, _handleSelfReference, _new, assignNullSerializer, assignSerializer, assignTypeSerializer, depositSchemaProperty, depositSchemaProperty, fixAccess, get, getAnnotation, getContextAnnotation, getFullName, getGenericPropertyType, getInternalSetting, getMember, getName, getPropertyType, getRawSerializationType, getSerializationType, getSerializedName, getSerializer, getType, getTypeSerializer, getViews, getWrapperName, hasNullSerializer, hasSerializer, isUnwrapping, removeInternalSetting, rename, serializeAsElement, serializeAsOmittedField, serializeAsPlaceholder, setInternalSetting, setNonTrivialBaseType, toString, unwrappingWriter, willSuppressNulls, wouldConflictWithName

    Methods inherited from class com.fasterxml.jackson.databind.ser.PropertyWriter

    findAnnotation

    Methods inherited from class com.fasterxml.jackson.databind.introspect.ConcreteBeanPropertyBase

    findAliases, findFormatOverrides, findPropertyFormat, findPropertyInclusion, getMetadata, isRequired, isVirtual

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PropertyMaskingSafePropertyWriter

      public PropertyMaskingSafePropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter base, List<String> maskedFieldRegexps)
      Construct new instance wrapping the given BeanPropertyWriter using the given list of (String) regular expressions that define the properties which should be masked.

      Default values for masked fields and serialization errors are used. The default values are defined by PropertyMaskingOptions.

      Parameters:
      base - the base or delegate BeanPropertyWriter to use
      maskedFieldRegexps - list containing regular expressions that define the properties to mask
    • PropertyMaskingSafePropertyWriter

      public PropertyMaskingSafePropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter base, PropertyMaskingOptions options)
      Construct new instance wrapping the given BeanPropertyWriter using the given PropertyMaskingOptions to define properties to be masked, as well as replacement text for masked fields and serialization errors.
      Parameters:
      base - the base or delegate BeanPropertyWriter to use
      options - the options to use
      See Also:
  • Method Details

    • serializeAsField

      public void serializeAsField(Object bean, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider prov)
      Overrides:
      serializeAsField in class com.fasterxml.jackson.databind.ser.BeanPropertyWriter