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.BeanPropertyWriterWrites 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 than 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
JsonViewinstead.Note that jackson-core and jackson-databind must be available at runtime.
- See Also:
- Serialized Form
-
-
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
-
-
Constructor Summary
Constructors Constructor Description PropertyMaskingSafePropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter base, List<String> maskedFieldRegexps)Construct new instance wrapping the givenBeanPropertyWriterusing 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 givenBeanPropertyWriterusing the givenPropertyMaskingOptionsto define properties to be masked, as well as replacement text for masked fields and serialization errors.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidserializeAsField(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
-
-
-
-
Constructor Detail
-
PropertyMaskingSafePropertyWriter
public PropertyMaskingSafePropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter base, List<String> maskedFieldRegexps)Construct new instance wrapping the givenBeanPropertyWriterusing 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 delegateBeanPropertyWriterto usemaskedFieldRegexps- 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 givenBeanPropertyWriterusing the givenPropertyMaskingOptionsto define properties to be masked, as well as replacement text for masked fields and serialization errors.- Parameters:
base- the base or delegateBeanPropertyWriterto useoptions- the options to use- See Also:
PropertyMaskingOptions
-
-
Method Detail
-
serializeAsField
public void serializeAsField(Object bean, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider prov)
- Overrides:
serializeAsFieldin classcom.fasterxml.jackson.databind.ser.BeanPropertyWriter
-
-