Java Records Support

Axon Data Protection Module 5.0 provides full support for Java records (introduced in Java 14 and finalized in Java 16). Records are immutable data carriers that are ideal for modeling events in event-sourced systems.

When working with records, the module creates new record instances with modified (encrypted/decrypted) field values, since records are immutable and their fields cannot be modified in-place. This is handled transparently by the module.

Example of a record-based event with personal data annotations:

public record PersonRegisteredEvent(
    @DataSubjectId UUID id,
    @PersonalData String name,
    @PersonalData byte[] picture,
    String city
) {}

All Axon Data Protection annotations (@DataSubjectId, @PersonalData, @SerializedPersonalData, @DeepPersonalData) work seamlessly with Java records. Nested records are also fully supported through the @DeepPersonalData annotation.