Custom Logical Types

Catalog of custom logical types included in this project

Type Catalog

🔒 Encrypted

Encrypts string fields using AES-GCM. The schema stores the cyphertext, but the application sees plain text.

  • Logical Type: encrypted
  • Underlying Type: bytes or string
  • Use case: PII, Secrets, PCI data

🔄 Reversed

A simple demo type that reverses the string value. Useful for understanding the conversion API.

  • Logical Type: reversed
  • Underlying Type: string

📧 Email (Normalized)

Automatically lowercases email addresses on write to ensure consistency.

  • Logical Type: email_lower
  • Underlying Type: string

📱 Phone (Normalized)

Strips formatting characters (dashes, spaces) and standardizes the format.

  • Logical Type: phone_normalized
  • Underlying Type: string

Create Your Own

The project includes a Gradle task to scaffold the boilerplate for a new logical type. This creates the LogicalType class, the Conversion class, and the Factory.

./gradlew newLogicalType -Pname=mask

What gets created?

  • MaskLogicalType.java defines the type name
  • MaskConversion.java handles the read/write logic
  • MaskLogicalTypeFactory.java registers it with Avro