Languages
[Edit]
EN

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

11 points
Created by:
illona
526

Using with DTO object

Edit

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.

 

Lombok - private final fields

Edit

Below we can see how to make all fields 'private final' using Lombok annotations. It is quite simple, we just use:

Complete example:

Notes

Default values in @FieldDefaults annotation:

  • By default access level is set to: NONE
  • By default make fianl is set to: false

 

Handle exceptions with lombok

Edit

 

Private constructors

Edit

 

Using with Hibernate entity

Edit

 

Lombok with logger - Slf4j

Edit

 

References

Edit
  1. Lombok all features - stable
  2. Lombok all features - experimental
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Lombok - java library

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.

❤️💻 🙂

Join