Skip to content

Single record options

pawel_labaj edited this page Aug 2, 2023 · 2 revisions

@AutoRecord.Options

You can customize the generation of a single record by using the @AutoRecord.Options annotation next to @AutoRecod. This annotation can be used to specify various options that will affect how the record is generated. Here are options that can be customized:

  • withBuilder - enable generation of a builder for the record; see Builders
  • memoizedHashCode - enable memoization of the hashCode() method; see hashCode memoization
  • memoizedToString - enable memoization of the toString() method; see toString memoization

@RecordBuilder.Options

If you enabled builder generation, you can customize it with @RecordBuilder.Options annotation. Please visit the Record Builder documentation for details.

@AutoRecord.Extension

You can attach a custom extensions to the generation process to enable specific features. Please see the Extensions page for details.

Example interface

Here's an example of how you would customize a record generation to enable builder generation and memoization of the hashCode() and toString() methods. Generated builder will add non-optional setter methods for optional record components. In addition, LoggingExtension and IsPersonAdultVerifierExtension extensions will be used during ht generation process.

@AutoRecord
@AutoRecord.Options(withBuilder = true, memoizedHashCode = true, memoizedToString = true)
@RecordBuilder.Options(addConcreteSettersForOptional = true)
@AutoRecord.Extension(extensionClass = LoggingExtension.class, parameters = "info")
@AutoRecord.Extension(extensionClass = IsPersonAdultVerifierExtension.class)
interface Person {
    String name();
}