Skip to content

Add fluent setters support for Record #61

Description

@ivan-arriola

Taking advantage of lates JDK versions, is possible to use the record type, for immutable objects, which reduce a lot the dependency from Lombok, nevertheless, the builder pattern (a.k.a. fluent), is a beautiful and clean way to develop mappers and logic around how you set field values of an object. I still use Lombok just for the @Builder, but it causes issues for native builds with Graalvm.

@Builder
public record Transaction (
    UUID id,
    BigDecimal amount,
    String merchant,
    Long date,
    Long createdAt
) { }

So, you can build something like:

  static Transaction toModel(TransactionEntity entity) {
      return Transaction
          .builder()
          .id(entity.id())
          .amount(entity.amount())
          .merchant(entity.merchant())
          .date(entity.date())
          .type(entity.type())
          .createdAt(entity.createdAt())
          .build();
    }

Today, if you try Generate Only Fluent Setters it causes an error (and ask you to submit an issue 😄)

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions