public class MaskingJsonGenerator extends JsonGeneratorDelegate
JsonGenerator that can mask sensitive field values before delegating to a delegate JsonGenerator.
MaskingJsonGenerator uses a collection of FieldMaskers
to identify fields to mask by JSON path.
These field maskers are invoked after a new field name is written to determine if the field's value should be masked. If any masker returns a non-null value, then the returned value will be written as the field's value (instead of the original field value). Note that the masked value's type might differ from the fields original type.
Example FieldMaskers:
MaskingJsonGenerator uses a collection of ValueMaskers
to mask field values by JSON path and field value.
These value maskers are invoked each time a new number or string scalar value is written to determine if the value should be masked. If all maskers return null, then the value is written as-is (i.e. not masked). If any masker returns non-null, then the returned value will be written as the field value.
Raw values are NOT masked.
It is much more efficient to mask field values by path, rather than by field value.
Therefore, prefer using FieldMaskers instead of ValueMaskers whenever possible.
Example value maskers:
JsonGenerator.Feature| Modifier and Type | Field and Description |
|---|---|
static String |
MASK |
delegate, delegateCopyMethods_cfgPrettyPrinter, DEFAULT_BINARY_WRITE_CAPABILITIES, DEFAULT_TEXTUAL_WRITE_CAPABILITIES, DEFAULT_WRITE_CAPABILITIES| Constructor and Description |
|---|
MaskingJsonGenerator(JsonGenerator delegate,
Collection<FieldMasker> fieldMaskers,
Collection<ValueMasker> valueMaskers) |
| Modifier and Type | Method and Description |
|---|---|
void |
writeArray(double[] array,
int offset,
int length) |
void |
writeArray(int[] array,
int offset,
int length) |
void |
writeArray(long[] array,
int offset,
int length) |
void |
writeBinary(Base64Variant b64variant,
byte[] data,
int offset,
int len) |
int |
writeBinary(Base64Variant b64variant,
InputStream data,
int dataLength) |
void |
writeBinary(byte[] data) |
void |
writeBinary(byte[] data,
int offset,
int len) |
int |
writeBinary(InputStream data,
int dataLength) |
void |
writeBoolean(boolean state) |
void |
writeEmbeddedObject(Object object) |
void |
writeEndArray() |
void |
writeEndObject() |
void |
writeFieldId(long id) |
void |
writeFieldName(SerializableString name) |
void |
writeFieldName(String name) |
void |
writeNull() |
void |
writeNumber(BigDecimal v) |
void |
writeNumber(BigInteger v) |
void |
writeNumber(double v) |
void |
writeNumber(float v) |
void |
writeNumber(int v) |
void |
writeNumber(long v) |
void |
writeNumber(short v) |
void |
writeNumber(String encodedValue) |
void |
writeObjectId(Object id) |
void |
writeObjectRef(Object id) |
void |
writeOmittedField(String fieldName) |
void |
writeRaw(char c) |
void |
writeRaw(char[] text,
int offset,
int len) |
void |
writeRaw(SerializableString raw) |
void |
writeRaw(String text) |
void |
writeRaw(String text,
int offset,
int len) |
void |
writeRawUTF8String(byte[] text,
int offset,
int length) |
void |
writeRawValue(char[] text,
int offset,
int len) |
void |
writeRawValue(String text) |
void |
writeRawValue(String text,
int offset,
int len) |
void |
writeStartArray() |
void |
writeStartArray(int size) |
void |
writeStartArray(Object forValue) |
void |
writeStartArray(Object forValue,
int size) |
void |
writeStartObject() |
void |
writeStartObject(Object forValue) |
void |
writeStartObject(Object forValue,
int size) |
void |
writeString(char[] text,
int offset,
int len) |
void |
writeString(Reader reader,
int len) |
void |
writeString(SerializableString text) |
void |
writeString(String text) |
void |
writeTypeId(Object id) |
void |
writeUTF8String(byte[] text,
int offset,
int length) |
assignCurrentValue, canOmitFields, canUseSchema, canWriteBinaryNatively, canWriteFormattedNumbers, canWriteObjectId, canWriteTypeId, close, copyCurrentEvent, copyCurrentStructure, currentValue, delegate, disable, enable, flush, getCharacterEscapes, getCodec, getCurrentValue, getDelegate, getFeatureMask, getHighestEscapedChar, getOutputBuffered, getOutputContext, getOutputTarget, getPrettyPrinter, getSchema, getWriteCapabilities, isClosed, isEnabled, overrideFormatFeatures, overrideStdFeatures, setCharacterEscapes, setCodec, setCurrentValue, setFeatureMask, setHighestNonEscapedChar, setPrettyPrinter, setRootValueSeparator, setSchema, useDefaultPrettyPrinter, version, writeArray, writeNumber, writeObject, writePOJO, writeTree_copyCurrentContents, _reportError, _reportUnsupportedOperation, _throwInternal, _verifyOffsets, _writeSimpleObject, configure, getFormatFeatures, isEnabled, writeArrayFieldStart, writeBinaryField, writeBooleanField, writeNullField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart, writePOJOField, writeRawValue, writeStringField, writeTypePrefix, writeTypeSuffixpublic static final String MASK
public MaskingJsonGenerator(JsonGenerator delegate, Collection<FieldMasker> fieldMaskers, Collection<ValueMasker> valueMaskers)
delegate - the generator to which to write potentially masked JSONfieldMaskers - FieldMaskers to mask fieldsvalueMaskers - ValueMaskers to mask valuespublic void writeArray(int[] array,
int offset,
int length)
throws IOException
writeArray in class JsonGeneratorDelegateIOExceptionpublic void writeArray(long[] array,
int offset,
int length)
throws IOException
writeArray in class JsonGeneratorDelegateIOExceptionpublic void writeArray(double[] array,
int offset,
int length)
throws IOException
writeArray in class JsonGeneratorDelegateIOExceptionpublic void writeFieldName(SerializableString name) throws IOException
writeFieldName in class JsonGeneratorDelegateIOExceptionpublic void writeFieldName(String name) throws IOException
writeFieldName in class JsonGeneratorDelegateIOExceptionpublic void writeFieldId(long id)
throws IOException
writeFieldId in class JsonGeneratorDelegateIOExceptionpublic void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) throws IOException
writeBinary in class JsonGeneratorDelegateIOExceptionpublic void writeBinary(byte[] data)
throws IOException
writeBinary in class JsonGeneratorIOExceptionpublic void writeBinary(byte[] data,
int offset,
int len)
throws IOException
writeBinary in class JsonGeneratorIOExceptionpublic int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) throws IOException
writeBinary in class JsonGeneratorDelegateIOExceptionpublic int writeBinary(InputStream data, int dataLength) throws IOException
writeBinary in class JsonGeneratorIOExceptionpublic void writeBoolean(boolean state)
throws IOException
writeBoolean in class JsonGeneratorDelegateIOExceptionpublic void writeEmbeddedObject(Object object) throws IOException
writeEmbeddedObject in class JsonGeneratorDelegateIOExceptionpublic void writeNull()
throws IOException
writeNull in class JsonGeneratorDelegateIOExceptionpublic void writeNumber(BigDecimal v) throws IOException
writeNumber in class JsonGeneratorDelegateIOExceptionpublic void writeNumber(BigInteger v) throws IOException
writeNumber in class JsonGeneratorDelegateIOExceptionpublic void writeNumber(double v)
throws IOException
writeNumber in class JsonGeneratorDelegateIOExceptionpublic void writeNumber(float v)
throws IOException
writeNumber in class JsonGeneratorDelegateIOExceptionpublic void writeNumber(int v)
throws IOException
writeNumber in class JsonGeneratorDelegateIOExceptionpublic void writeNumber(short v)
throws IOException
writeNumber in class JsonGeneratorDelegateIOExceptionpublic void writeNumber(long v)
throws IOException
writeNumber in class JsonGeneratorDelegateIOExceptionpublic void writeNumber(String encodedValue) throws IOException
writeNumber in class JsonGeneratorDelegateIOExceptionpublic void writeObjectId(Object id) throws IOException
writeObjectId in class JsonGeneratorDelegateIOExceptionpublic void writeObjectRef(Object id) throws IOException
writeObjectRef in class JsonGeneratorDelegateIOExceptionpublic void writeOmittedField(String fieldName) throws IOException
writeOmittedField in class JsonGeneratorDelegateIOExceptionpublic void writeRaw(char c)
throws IOException
writeRaw in class JsonGeneratorDelegateIOExceptionpublic void writeRaw(char[] text,
int offset,
int len)
throws IOException
writeRaw in class JsonGeneratorDelegateIOExceptionpublic void writeRaw(String text) throws IOException
writeRaw in class JsonGeneratorDelegateIOExceptionpublic void writeRaw(String text, int offset, int len) throws IOException
writeRaw in class JsonGeneratorDelegateIOExceptionpublic void writeRaw(SerializableString raw) throws IOException
writeRaw in class JsonGeneratorDelegateIOExceptionpublic void writeRawValue(String text) throws IOException
writeRawValue in class JsonGeneratorDelegateIOExceptionpublic void writeRawValue(String text, int offset, int len) throws IOException
writeRawValue in class JsonGeneratorDelegateIOExceptionpublic void writeRawValue(char[] text,
int offset,
int len)
throws IOException
writeRawValue in class JsonGeneratorDelegateIOExceptionpublic void writeRawUTF8String(byte[] text,
int offset,
int length)
throws IOException
writeRawUTF8String in class JsonGeneratorDelegateIOExceptionpublic void writeStartArray(int size)
throws IOException
writeStartArray in class JsonGeneratorDelegateIOExceptionpublic void writeStartArray()
throws IOException
writeStartArray in class JsonGeneratorDelegateIOExceptionpublic void writeStartArray(Object forValue) throws IOException
writeStartArray in class JsonGeneratorDelegateIOExceptionpublic void writeStartArray(Object forValue, int size) throws IOException
writeStartArray in class JsonGeneratorDelegateIOExceptionpublic void writeStartObject()
throws IOException
writeStartObject in class JsonGeneratorDelegateIOExceptionpublic void writeStartObject(Object forValue) throws IOException
writeStartObject in class JsonGeneratorDelegateIOExceptionpublic void writeStartObject(Object forValue, int size) throws IOException
writeStartObject in class JsonGeneratorDelegateIOExceptionpublic void writeString(char[] text,
int offset,
int len)
throws IOException
writeString in class JsonGeneratorDelegateIOExceptionpublic void writeString(String text) throws IOException
writeString in class JsonGeneratorDelegateIOExceptionpublic void writeString(SerializableString text) throws IOException
writeString in class JsonGeneratorDelegateIOExceptionpublic void writeString(Reader reader, int len) throws IOException
writeString in class JsonGeneratorDelegateIOExceptionpublic void writeUTF8String(byte[] text,
int offset,
int length)
throws IOException
writeUTF8String in class JsonGeneratorDelegateIOExceptionpublic void writeTypeId(Object id) throws IOException
writeTypeId in class JsonGeneratorDelegateIOExceptionpublic void writeEndArray()
throws IOException
writeEndArray in class JsonGeneratorDelegateIOExceptionpublic void writeEndObject()
throws IOException
writeEndObject in class JsonGeneratorDelegateIOExceptionCopyright © 2013–2022. All rights reserved.