Lombok
@Data
@AllArgsConstructor
@RequiredArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
And Special
@Singular
@NonNull
@Cleanup
@Value
@SneakyThrows
@Log
@With
MapStruct
Multi-layered applications often require to map between different object models (e.g. entities and DTOs). Writing such mapping code is a tedious and error-prone task. MapStruct aims at simplifying this work by automating it as much as possible.
In contrast to other mapping frameworks MapStruct generates bean mappings at compile-time which ensures a high performance, allows for fast developer feedback and thorough error checking.
- public class Car {
- private String make;
- private int numberOfSeats;
- private CarType type;
- //constructor, getters, setters etc.
- }
- public class CarDto {
- private String make;
- private int seatCount;
- private String type;
- //constructor, getters, setters etc.
- }
Here we define the Mapper. So after compilation the carToCarDto method is implemented as simple java code.
- @Mapper 1
- public interface CarMapper {
- CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); 3
- @Mapping(source = "numberOfSeats", target = "seatCount")
- CarDto carToCarDto(Car car); 2
- }
How to add AnnotationProcessor in gradle.
https://tomgregory.com/annotation-processors-in-gradle-with-the-annotationprocessor-dependency-configuration/