Lombok - most popular usage combinations of Lombok annotations on DTO objects in java

11 points
Created by:

Using with DTO object

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;

@FieldDefaults(level = AccessLevel.PRIVATE)
public class AddPostRequest {
    String postName;
    String postBody;

Why to use @NoArgsConstructor ?

We can use this DTO with json libraries that requires empty constructor. All fiels will be private and we have all args contructor annotation if we want to create object in this way.

Using with Hibernate entity

@FieldDefaults(level = AccessLevel.PRIVATE)
@Table(name = "posts")
public class PostsEntity {

    Long id;
    String title;
	// ..

Lombok with logger - Slf4j

import lombok.extern.slf4j.Slf4j;

public class LombokWithLogger {

    public static void main(String[] args) {"Log info");
        log.error("Log error");
        // internally it uses:
        // org.slf4j


  1. Lombok all features - stable
  2. Lombok all features - experimental
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé