Class Records

java.lang.Object
io.beanmapper.utils.Records

public final class Records extends Object

Utility-class for methods commonly used when mapping to and from records.

  • Method Details

    • getRecordFieldNames

      public static String[] getRecordFieldNames(Class<? extends Record> clazz)

      Gets the names of all the fields that are passed to the given record through the constructor.

      By using the names of RecordComponent-objects, this method won't map any of the static fields a record may contain.

      Parameters:
      clazz - The record of which the names of the RecordComponent-objects will be returned.
      Returns:
      An array containing the names of the RecordComponent-objects.
    • getCanonicalConstructorOfRecord

      public static <R extends Record> Constructor<R> getCanonicalConstructorOfRecord(Class<R> recordClass)
      Gets the canonical constructor of the given record.

      The canonical constructor is the constructor in a record, that is automatically generated based off of the signature of the record. A canonical constructor requires every RecordComponent as its parameter, in the order they were declared in.

      Based off of the requirements for a canonical constructor, we can retrieve the canonical constructor by creating an array of the types of the RecordComponents, in the correct order, and calling Class.getDeclaredConstructor(Class[])

      Type Parameters:
      R - The type of the record.
      Parameters:
      recordClass - The type of the record.
      Returns:
      The canonical constructor of the record.
    • getConstructorsAnnotatedWithRecordConstruct

      public static <R> Collection<Constructor<R>> getConstructorsAnnotatedWithRecordConstruct(Class<R> recordClass)
      Gets all constructors of the target record, annotated with @RecordConstruct, without the option constructMode = BeanRecordConstructMode.EXCLUDE.
      Type Parameters:
      R - The type of the record-class.
      Parameters:
      recordClass - The record-class of which the constructors will be retrieved.
      Returns:
      The collection of constructors annotated with the @RecordConstruct-annotation.