vscode-java-code-generator icon indicating copy to clipboard operation
vscode-java-code-generator copied to clipboard

Add fluent setters support for Record

Open iarriola opened this issue 1 year ago • 0 comments

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

iarriola avatar Sep 21 '23 05:09 iarriola