Skip to content

Instantly share code, notes, and snippets.

@kjivan
Last active February 25, 2025 04:10
Show Gist options
  • Select an option

  • Save kjivan/a34311e206ce0e3a3e2b5e3f8f594517 to your computer and use it in GitHub Desktop.

Select an option

Save kjivan/a34311e206ce0e3a3e2b5e3f8f594517 to your computer and use it in GitHub Desktop.

Revisions

  1. kjivan revised this gist Feb 25, 2025. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -21,5 +21,6 @@
    * This makes them required cuasing them to be included in the constructor and therefore [injection](https://www.baeldung.com/constructor-injection-in-spring)
    * Make [`@Value`](https://www.baeldung.com/spring-value-annotation) class variables `private`
    * These values are not constuctor injected
    * Do not use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter) data in services should not be used by anyone else
    * Do not use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * data in services should not be used by anyone else
    * For testing use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
  2. kjivan revised this gist Feb 25, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    * Do not use [`@Data`](https://projectlombok.org/features/Data) and [`@EqualsAndHashCode`](https://projectlombok.org/features/EqualsAndHashCode)
    * Use [`@Getter`](https://projectlombok.org/features/GetterSetter) and [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * Don't forget to exclude lazy attributes if you use [`@ToString`](https://projectlombok.org/features/ToString)
    * Don't forget to add [`@NoArgsConstructor`](https://projectlombok.org/features/constructor) if you use [`@Builder`](https://projectlombok.org/features/Builder) or [`@FullArgsConstructor`](https://projectlombok.org/features/constructor) or [`@RequiredArgsConstructor`](https://projectlombok.org/features/constructor)
    * Don't forget to add [`@NoArgsConstructor`](https://projectlombok.org/features/constructor) if you use [`@Builder`](https://projectlombok.org/features/Builder) or [`@AllArgsConstructor`](https://projectlombok.org/features/constructor) or [`@RequiredArgsConstructor`](https://projectlombok.org/features/constructor)
    * Explanation for rules above: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)
    * Use [`@Builder`](https://projectlombok.org/features/Builder) if setting lots of different fields

  3. kjivan revised this gist Feb 14, 2024. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    # Lombok Best Practices

    ## Entities
    * Should not use [`@Data`](https://projectlombok.org/features/Data) and [`@EqualsAndHashCode`](https://projectlombok.org/features/EqualsAndHashCode)
    * If you use [`@ToString`](https://projectlombok.org/features/ToString) don't forget to exclude lazy attributes
    * Do not use [`@Data`](https://projectlombok.org/features/Data) and [`@EqualsAndHashCode`](https://projectlombok.org/features/EqualsAndHashCode)
    * Use [`@Getter`](https://projectlombok.org/features/GetterSetter) and [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * Don't forget to exclude lazy attributes if you use [`@ToString`](https://projectlombok.org/features/ToString)
    * Don't forget to add [`@NoArgsConstructor`](https://projectlombok.org/features/constructor) if you use [`@Builder`](https://projectlombok.org/features/Builder) or [`@FullArgsConstructor`](https://projectlombok.org/features/constructor) or [`@RequiredArgsConstructor`](https://projectlombok.org/features/constructor)
    * Explanation for rules above: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)
    * Add [`@Builder`](https://projectlombok.org/features/Builder) if setting lots of different fields
    * Use [`@Builder`](https://projectlombok.org/features/Builder) if setting lots of different fields

    ## DTOs/POJOs/Classes with just member variables to store data
    * Use [`@Data`](https://projectlombok.org/features/Data)
    * Most pojos can benefit from all the features of [`@Data`](https://projectlombok.org/features/Data) with no notable side effects
    * [`@Data`](https://projectlombok.org/features/Data) is a convenient shortcut annotation that bundles the features of [`@ToString`](https://projectlombok.org/features/ToString), [`@EqualsAndHashCode`](https://projectlombok.org/features/EqualsAndHashCode), [`@Getter`](https://projectlombok.org/features/GetterSetter) / [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * Add [`@Builder`](https://projectlombok.org/features/Builder) if setting lots of different fields
    * Use [`@Builder`](https://projectlombok.org/features/Builder) if setting lots of different fields
    * [Explanation of DTOs,POJOs](https://www.baeldung.com/java-pojo-javabeans-dto-vo)

    ## Services
    @@ -21,5 +21,5 @@
    * This makes them required cuasing them to be included in the constructor and therefore [injection](https://www.baeldung.com/constructor-injection-in-spring)
    * Make [`@Value`](https://www.baeldung.com/spring-value-annotation) class variables `private`
    * These values are not constuctor injected
    * Don't use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter) data in services should not be used by anyone else
    * Do not use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter) data in services should not be used by anyone else
    * For testing use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
  4. kjivan revised this gist Feb 14, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,13 @@
    * Use [`@Getter`](https://projectlombok.org/features/GetterSetter) and [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * Don't forget to add [`@NoArgsConstructor`](https://projectlombok.org/features/constructor) if you use [`@Builder`](https://projectlombok.org/features/Builder) or [`@FullArgsConstructor`](https://projectlombok.org/features/constructor) or [`@RequiredArgsConstructor`](https://projectlombok.org/features/constructor)
    * Explanation for rules above: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)
    * Add [`@Builder`](https://projectlombok.org/features/Builder) if setting lots of different fields

    ## DTOs/POJOs/Classes with just member variables to store data
    * Use [`@Data`](https://projectlombok.org/features/Data)
    * Most pojos can benefit from all the features of [`@Data`](https://projectlombok.org/features/Data) with no notable side effects
    * [`@Data`](https://projectlombok.org/features/Data) is a convenient shortcut annotation that bundles the features of [`@ToString`](https://projectlombok.org/features/ToString), [`@EqualsAndHashCode`](https://projectlombok.org/features/EqualsAndHashCode), [`@Getter`](https://projectlombok.org/features/GetterSetter) / [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * Add [`@Builder`](https://projectlombok.org/features/Builder)
    * Add [`@Builder`](https://projectlombok.org/features/Builder) if setting lots of different fields
    * [Explanation of DTOs,POJOs](https://www.baeldung.com/java-pojo-javabeans-dto-vo)

    ## Services
  5. kjivan revised this gist Feb 14, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,5 @@
    * This makes them required cuasing them to be included in the constructor and therefore [injection](https://www.baeldung.com/constructor-injection-in-spring)
    * Make [`@Value`](https://www.baeldung.com/spring-value-annotation) class variables `private`
    * These values are not constuctor injected
    * Don't use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter) data in service should not be used by anyone else
    * Don't use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter) data in services should not be used by anyone else
    * For testing use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
  6. kjivan revised this gist Feb 14, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,5 @@
    * This makes them required cuasing them to be included in the constructor and therefore [injection](https://www.baeldung.com/constructor-injection-in-spring)
    * Make [`@Value`](https://www.baeldung.com/spring-value-annotation) class variables `private`
    * These values are not constuctor injected
    * Don't use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter) data in services should be private
    * Don't use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter) data in service should not be used by anyone else
    * For testing use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
  7. kjivan revised this gist Feb 14, 2024. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -4,21 +4,21 @@
    * Should not use [`@Data`](https://projectlombok.org/features/Data) and [`@EqualsAndHashCode`](https://projectlombok.org/features/EqualsAndHashCode)
    * If you use [`@ToString`](https://projectlombok.org/features/ToString) don't forget to exclude lazy attributes
    * Use [`@Getter`](https://projectlombok.org/features/GetterSetter) and [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * Don't forget to add [`@NoArgsConstructor`](https://projectlombok.org/features/NoArgsConstructor) if you use [`@Builder`](https://projectlombok.org/features/Builder) or [`@FullArgsConstructor`](https://projectlombok.org/features/FullArgsConstructor) or [`@RequiredArgsConstructor`](https://projectlombok.org/features/RequiredArgsConstructor)
    * Don't forget to add [`@NoArgsConstructor`](https://projectlombok.org/features/constructor) if you use [`@Builder`](https://projectlombok.org/features/Builder) or [`@FullArgsConstructor`](https://projectlombok.org/features/constructor) or [`@RequiredArgsConstructor`](https://projectlombok.org/features/constructor)
    * Explanation for rules above: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)

    ## DTOs/POJOs/Classes with just member variables to store data
    * Use [`@Data`](https://projectlombok.org/features/Data)
    * Most pojos can benefit from all the features of [`@Data`](https://projectlombok.org/features/Data) with no notable side effects
    * [`@Data`](https://projectlombok.org/features/Data) is a convenient shortcut annotation that bundles the features of @ToString, @EqualsAndHashCode, @Getter / @Setter
    * [`@Data`](https://projectlombok.org/features/Data) is a convenient shortcut annotation that bundles the features of [`@ToString`](https://projectlombok.org/features/ToString), [`@EqualsAndHashCode`](https://projectlombok.org/features/EqualsAndHashCode), [`@Getter`](https://projectlombok.org/features/GetterSetter) / [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * Add [`@Builder`](https://projectlombok.org/features/Builder)
    * [Explanation of DTOs,POJOs](https://www.baeldung.com/java-pojo-javabeans-dto-vo)

    ## Services
    * Use `@RequiredArgsConstructor`
    * Use [`@RequiredArgsConstructor`](https://projectlombok.org/features/constructor)
    * Make dependency injected class variables `private final`
    * This makes them required and therefore will be included in the constructor and therefore [injected](https://www.baeldung.com/constructor-injection-in-spring)
    * Make `@Value` class variables `private`
    * This makes them required cuasing them to be included in the constructor and therefore [injection](https://www.baeldung.com/constructor-injection-in-spring)
    * Make [`@Value`](https://www.baeldung.com/spring-value-annotation) class variables `private`
    * These values are not constuctor injected
    * Don't use `@Data` , `@Getter` , `@Setter` data in services should be private
    * Don't use [`@Data`](https://projectlombok.org/features/Data) , [`@Getter`](https://projectlombok.org/features/GetterSetter) , [`@Setter`](https://projectlombok.org/features/GetterSetter) data in services should be private
    * For testing use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
  8. kjivan revised this gist Feb 14, 2024. 1 changed file with 13 additions and 9 deletions.
    22 changes: 13 additions & 9 deletions lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,24 @@
    # Lombok Best Practices

    ## Entities
    * Should not use `@Data` and `@EqualsAndHashCode`
    * If you use `@ToString` don't forget to exclude lazy attributes
    * Use `@Getter` and `@Setter`
    * Don't forget to add `@NoArgsConstructor` if you use `@Builder` or `@FullArgsConstructor` or `@RequiredArgsConstructor`
    * Should not use [`@Data`](https://projectlombok.org/features/Data) and [`@EqualsAndHashCode`](https://projectlombok.org/features/EqualsAndHashCode)
    * If you use [`@ToString`](https://projectlombok.org/features/ToString) don't forget to exclude lazy attributes
    * Use [`@Getter`](https://projectlombok.org/features/GetterSetter) and [`@Setter`](https://projectlombok.org/features/GetterSetter)
    * Don't forget to add [`@NoArgsConstructor`](https://projectlombok.org/features/NoArgsConstructor) if you use [`@Builder`](https://projectlombok.org/features/Builder) or [`@FullArgsConstructor`](https://projectlombok.org/features/FullArgsConstructor) or [`@RequiredArgsConstructor`](https://projectlombok.org/features/RequiredArgsConstructor)
    * Explanation for rules above: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)

    ## DTOs/POJOs/Classes with just member variables to store data
    * Use `@Data`
    * Use [`@Data`](https://projectlombok.org/features/Data)
    * Most pojos can benefit from all the features of [`@Data`](https://projectlombok.org/features/Data) with no notable side effects
    * [`@Data`](https://projectlombok.org/features/Data) is a convenient shortcut annotation that bundles the features of @ToString, @EqualsAndHashCode, @Getter / @Setter
    * Add [`@Builder`](https://projectlombok.org/features/Builder)
    * [Explanation of DTOs,POJOs](https://www.baeldung.com/java-pojo-javabeans-dto-vo)

    ## Services
    * Use `@RequiredArgsConstructor`
    * Make dependency injected values `private final`
    * This will force the generated constructor to use them
    * Make `@Value` values `private`
    * These are not injected via a constructor so they shouldn't be included
    * Make dependency injected class variables `private final`
    * This makes them required and therefore will be included in the constructor and therefore [injected](https://www.baeldung.com/constructor-injection-in-spring)
    * Make `@Value` class variables `private`
    * These values are not constuctor injected
    * Don't use `@Data` , `@Getter` , `@Setter` data in services should be private
    * For testing use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
  9. kjivan revised this gist Feb 14, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,8 @@
    ## Services
    * Use `@RequiredArgsConstructor`
    * Make dependency injected values `private final`
    * This will force the generated constructor to use them
    * Make `@Value` values `private`
    * These are not injected via a constructor so they shouldn't be included
    * Don't use `@Data` , `@Getter` , `@Setter` data in services should be private
    * For testing use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
  10. kjivan revised this gist Feb 14, 2024. No changes.
  11. kjivan revised this gist Feb 14, 2024. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -4,15 +4,15 @@
    * Should not use `@Data` and `@EqualsAndHashCode`
    * If you use `@ToString` don't forget to exclude lazy attributes
    * Use `@Getter` and `@Setter`
    * Don't forget to add `@NoArgsConstructor` if you use `@Builder` or `@RequiredArgsConstructor` or `@FullArgsConstructor`
    * Reference: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)
    * Don't forget to add `@NoArgsConstructor` if you use `@Builder` or `@FullArgsConstructor` or `@RequiredArgsConstructor`
    * Explanation for rules above: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)

    ## DTOs/POJOs/Classes with just member variables to store data
    * Use `@Data`

    ## Services
    * Generally don't use `@Data` , `@Getter` , `@Setter` most of the data in services should be private
    ** For tests use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
    * Use `@RequiredArgsConstructor`
    ** Make dependency injected values `private final`
    ** Make `@Value` values `private`
    * Make dependency injected values `private final`
    * Make `@Value` values `private`
    * Don't use `@Data` , `@Getter` , `@Setter` data in services should be private
    * For testing use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
  12. kjivan revised this gist Feb 12, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    * Should not use `@Data` and `@EqualsAndHashCode`
    * If you use `@ToString` don't forget to exclude lazy attributes
    * Use `@Getter` and `@Setter`
    * Don't forget to add `@NoArgsConstructor` if you use `@Builder` or `@NoArgsConstructor`
    * Don't forget to add `@NoArgsConstructor` if you use `@Builder` or `@RequiredArgsConstructor` or `@FullArgsConstructor`
    * Reference: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)

    ## DTOs/POJOs/Classes with just member variables to store data
  13. kjivan revised this gist Jan 23, 2024. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    # Lombok Best Practices
    # Lombok Best Practices

    ## Entities
    * Should not use `@Data` and `@EqualsAndHashCode`
  14. kjivan created this gist Jan 23, 2024.
    19 changes: 19 additions & 0 deletions lombok-best-practices.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # Lombok Best Practices
    # Lombok Best Practices

    ## Entities
    * Should not use `@Data` and `@EqualsAndHashCode`
    * If you use `@ToString` don't forget to exclude lazy attributes
    * Use `@Getter` and `@Setter`
    * Don't forget to add `@NoArgsConstructor` if you use `@Builder` or `@NoArgsConstructor`
    * Reference: [Lombok and JPA: What may go wrong?](https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/)

    ## DTOs/POJOs/Classes with just member variables to store data
    * Use `@Data`

    ## Services
    * Generally don't use `@Data` , `@Getter` , `@Setter` most of the data in services should be private
    ** For tests use ⁠[ReflectionTestUtils](https://www.baeldung.com/spring-reflection-test-utils)
    * Use `@RequiredArgsConstructor`
    ** Make dependency injected values `private final`
    ** Make `@Value` values `private`