public class MaskingJsonGenerator extends JsonGeneratorDelegate
JsonGenerator
that can mask sensitive field values before delegating to a delegate JsonGenerator
.
MaskingJsonGenerator
uses a collection of FieldMasker
s
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 FieldMasker
s:
MaskingJsonGenerator
uses a collection of ValueMasker
s
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 FieldMasker
s instead of ValueMasker
s 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, writeTypeSuffix
public static final String MASK
public MaskingJsonGenerator(JsonGenerator delegate, Collection<FieldMasker> fieldMaskers, Collection<ValueMasker> valueMaskers)
delegate
- the generator to which to write potentially masked JSONfieldMaskers
- FieldMasker
s to mask fieldsvalueMaskers
- ValueMasker
s to mask valuespublic void writeArray(int[] array, int offset, int length) throws IOException
writeArray
in class JsonGeneratorDelegate
IOException
public void writeArray(long[] array, int offset, int length) throws IOException
writeArray
in class JsonGeneratorDelegate
IOException
public void writeArray(double[] array, int offset, int length) throws IOException
writeArray
in class JsonGeneratorDelegate
IOException
public void writeFieldName(SerializableString name) throws IOException
writeFieldName
in class JsonGeneratorDelegate
IOException
public void writeFieldName(String name) throws IOException
writeFieldName
in class JsonGeneratorDelegate
IOException
public void writeFieldId(long id) throws IOException
writeFieldId
in class JsonGeneratorDelegate
IOException
public void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) throws IOException
writeBinary
in class JsonGeneratorDelegate
IOException
public void writeBinary(byte[] data) throws IOException
writeBinary
in class JsonGenerator
IOException
public void writeBinary(byte[] data, int offset, int len) throws IOException
writeBinary
in class JsonGenerator
IOException
public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) throws IOException
writeBinary
in class JsonGeneratorDelegate
IOException
public int writeBinary(InputStream data, int dataLength) throws IOException
writeBinary
in class JsonGenerator
IOException
public void writeBoolean(boolean state) throws IOException
writeBoolean
in class JsonGeneratorDelegate
IOException
public void writeEmbeddedObject(Object object) throws IOException
writeEmbeddedObject
in class JsonGeneratorDelegate
IOException
public void writeNull() throws IOException
writeNull
in class JsonGeneratorDelegate
IOException
public void writeNumber(BigDecimal v) throws IOException
writeNumber
in class JsonGeneratorDelegate
IOException
public void writeNumber(BigInteger v) throws IOException
writeNumber
in class JsonGeneratorDelegate
IOException
public void writeNumber(double v) throws IOException
writeNumber
in class JsonGeneratorDelegate
IOException
public void writeNumber(float v) throws IOException
writeNumber
in class JsonGeneratorDelegate
IOException
public void writeNumber(int v) throws IOException
writeNumber
in class JsonGeneratorDelegate
IOException
public void writeNumber(short v) throws IOException
writeNumber
in class JsonGeneratorDelegate
IOException
public void writeNumber(long v) throws IOException
writeNumber
in class JsonGeneratorDelegate
IOException
public void writeNumber(String encodedValue) throws IOException
writeNumber
in class JsonGeneratorDelegate
IOException
public void writeObjectId(Object id) throws IOException
writeObjectId
in class JsonGeneratorDelegate
IOException
public void writeObjectRef(Object id) throws IOException
writeObjectRef
in class JsonGeneratorDelegate
IOException
public void writeOmittedField(String fieldName) throws IOException
writeOmittedField
in class JsonGeneratorDelegate
IOException
public void writeRaw(char c) throws IOException
writeRaw
in class JsonGeneratorDelegate
IOException
public void writeRaw(char[] text, int offset, int len) throws IOException
writeRaw
in class JsonGeneratorDelegate
IOException
public void writeRaw(String text) throws IOException
writeRaw
in class JsonGeneratorDelegate
IOException
public void writeRaw(String text, int offset, int len) throws IOException
writeRaw
in class JsonGeneratorDelegate
IOException
public void writeRaw(SerializableString raw) throws IOException
writeRaw
in class JsonGeneratorDelegate
IOException
public void writeRawValue(String text) throws IOException
writeRawValue
in class JsonGeneratorDelegate
IOException
public void writeRawValue(String text, int offset, int len) throws IOException
writeRawValue
in class JsonGeneratorDelegate
IOException
public void writeRawValue(char[] text, int offset, int len) throws IOException
writeRawValue
in class JsonGeneratorDelegate
IOException
public void writeRawUTF8String(byte[] text, int offset, int length) throws IOException
writeRawUTF8String
in class JsonGeneratorDelegate
IOException
public void writeStartArray(int size) throws IOException
writeStartArray
in class JsonGeneratorDelegate
IOException
public void writeStartArray() throws IOException
writeStartArray
in class JsonGeneratorDelegate
IOException
public void writeStartArray(Object forValue) throws IOException
writeStartArray
in class JsonGeneratorDelegate
IOException
public void writeStartArray(Object forValue, int size) throws IOException
writeStartArray
in class JsonGeneratorDelegate
IOException
public void writeStartObject() throws IOException
writeStartObject
in class JsonGeneratorDelegate
IOException
public void writeStartObject(Object forValue) throws IOException
writeStartObject
in class JsonGeneratorDelegate
IOException
public void writeStartObject(Object forValue, int size) throws IOException
writeStartObject
in class JsonGeneratorDelegate
IOException
public void writeString(char[] text, int offset, int len) throws IOException
writeString
in class JsonGeneratorDelegate
IOException
public void writeString(String text) throws IOException
writeString
in class JsonGeneratorDelegate
IOException
public void writeString(SerializableString text) throws IOException
writeString
in class JsonGeneratorDelegate
IOException
public void writeString(Reader reader, int len) throws IOException
writeString
in class JsonGeneratorDelegate
IOException
public void writeUTF8String(byte[] text, int offset, int length) throws IOException
writeUTF8String
in class JsonGeneratorDelegate
IOException
public void writeTypeId(Object id) throws IOException
writeTypeId
in class JsonGeneratorDelegate
IOException
public void writeEndArray() throws IOException
writeEndArray
in class JsonGeneratorDelegate
IOException
public void writeEndObject() throws IOException
writeEndObject
in class JsonGeneratorDelegate
IOException
Copyright © 2013–2021. All rights reserved.