Annotation Interface BeanRecordConstruct


@Retention(RUNTIME) @Target(CONSTRUCTOR) public @interface BeanRecordConstruct
An annotation applicable to Record-classes, that can be used to force BeanMapper to use a specific constructor of a record.

By default, BeanMapper will use the canonical constructor of a record. However, when a source-class contains fewer fields than the amount of RecordComponent-objects of the record, it may be wise to declare an overloaded constructor that allows the user to set only those fields that are present in the source, and fills the remaining fields with default values.

If a record contains multiple overloaded constructors, this annotation may offer some clarity. By setting the constructMode()-field of the annotation, the user may give hints on which constructor BeanMapper should use. This is especially useful in cases where BeanMapper should only use a specific constructor, or should exclude certain from consideration.

Annotating multiple constructors with the BeanRecordConstructMode.FORCE-option will lead to a RecordConstructorConflictException being thrown.

Annotating a single constructor with BeanRecordConstructMode.FORCE, and (an)other constructor(s) with BeanRecordConstructMode.ON_DEMAND will always result in the constructor annotated with the RecordConstructMode.FORCE-option being used. This will, however, not throw an Exception, as it will not cause any issues for BeanMapper.

Annotating a constructor with the BeanRecordConstructMode.EXCLUDE-option, will actively exclude that constructor from consideration.

Annotating all constructors with the RecordConstructMode.EXCLUDE-option, will result in a RecordNoAvailableConstructorsExceptions being thrown.

See Also:
  • Element Details

    • value

      String[] value
      Should contain the names of the fields that need to be used to invoke the constructor.
      Returns:
      The names of the fields that will be used to invoke the constructor.
      Default:
      {""}
    • constructMode

      Default:
      ON_DEMAND
    • allowNull

      boolean allowNull
      Default:
      false