<a id="maskfield"></a>

# Kafka Connect MaskField SMT Usage Reference for Confluent Platform

The `MaskField` SMT (`org.apache.kafka.connect.transforms.MaskField`) masks
one or more fields in an Apache Kafka® record key or value, either with a
type-appropriate null value or with a custom replacement value.

## Description

Use `MaskField` for either of the following scenarios:

* Replace any string or numeric field using the `replacement` property.
* Mask specified fields with a valid null value for the following field types:
  - Boolean: Boolean.FALSE
  - Byte: (byte) 0
  - Short: (short) 0
  - Integer: 0
  - Long: 0L
  - Float: 0f
  - Double: 0d
  - BigInteger: BigInteger.ZERO
  - BigDecimal: BigDecimal.ZERO
  - Date: new Date(0)
  - String: “”

Use the concrete transformation type designed for the record key
(`org.apache.kafka.connect.transforms.MaskField$Key`) or value
(`org.apache.kafka.connect.transforms.MaskField$Value`).

<a id="maskfield-properties"></a>

## Properties

| Name                        | Description                                                                                                                                                | Type    | Default   | Valid values                                                                           | Importance   |
|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|-----------|----------------------------------------------------------------------------------------|--------------|
| `fields`                    | Names of fields to mask.                                                                                                                                   | list    |           | non-empty list                                                                         | high         |
| `replacement`               | Custom value replacement applied to all `fields` values.                                                                                                   | string  | null      | non-empty string with a numeric or text value that can be converted to `fields` types. | low          |
| `replace.null.with.default` | Specifies whether to replace null fields with their defined default value. When `true`, the default value is applied. Otherwise, the field remains `null`. | boolean | true      |                                                                                        | medium       |

## Examples

### Mask value

This configuration snippet shows how to use `MaskField` to mask the value of a
field.

```json
"transforms": "MaskField",
"transforms.MaskField.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.MaskField.fields": "string_field"
```

This masks `string_field`, transforming the original message as shown
here:

`{"integer_field":22, "string_field":"foo"}`

into the result here:

`{"integer_field":22, "string_field":""}`

### Replace value

This configuration snippet shows how to use `MaskField` to replace the value
of a field. The example includes three transformations. The first and second
replace a value in a single field. The third is applied to both `office` and
`mobile` phone number fields.

```json
"transforms": "SSNMask,IPMask,PhoneMask",

"transforms.SSNMask.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.SSNMask.fields": "SSN",
"transforms.SSNMask.replacement": "***-***-****",

"transforms.IPMask.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.IPMask.fields": "IPAddress",
"transforms.IPMask.replacement": "xxx.xxx.xxx.xxx",

"transforms.PhoneMask.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.PhoneMask.fields": "office,mobile",
"transforms.PhoneMask.replacement": "+0-000-000-0000"
```

## Predicates

Configure transformations with predicates to ensure they process only records
that satisfy a particular condition. You can also use predicates in a
transformation chain with the [Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Platform](filter-ak.md#ak-filter) to conditionally filter specific
records. For more information, see [Predicates](filter-ak.md#predicates).
