Yes, Lombok is a widely used library and I too have used it extensively (www.sivalabs.in/should-you-use-lombok-or-is-it-bad-for-you/). I never had any trouble while using Lombok alone, but when used it with other annotation processors like MapStruct, AutoValue then there are some issues.
Hi Siva. I have seen your IntelliJ Session hosted by Mala Gupta (very, very good presentation by the way) and there you have used Spring Projections to create Dtos, instead of using MapStruct. Would you still recommend Spring Projections instead of MapStruct on enterprise applications development? Thanks for the video.
By using Spring Projection you can load only the columns you need. But using MapStruct you load entire entity first and then map the required properties to a DTO. This may result in loading unnecessary data. So, I would recommend to use either interface-based projections or class-based projections to load only the required data from database. An important thing to consider is, we can't load nested objects while using class-based projections, but it is possible with interface-based projections.
Regarding MapStuct, does it support expression/ conditional kind of conversion? Like suppose, I have a wrapper class Boolean in Entity. But I want to pass primitive boolean to DTO. Expression will be flag == null ? false : true flag is wrapper Boolean class in Entity.
Yes, it checks for null and assign the correct value as follows: boolean active = false; if ( user.active() != null ) { active = user.active(); } UserDTO userDTO = new UserDTO( id, fullName, emailAddress, active );
Lombok library provides record builder functionality. It is way more used in the industry in enterprise level.
Yes, Lombok is a widely used library and I too have used it extensively (www.sivalabs.in/should-you-use-lombok-or-is-it-bad-for-you/). I never had any trouble while using Lombok alone, but when used it with other annotation processors like MapStruct, AutoValue then there are some issues.
Thank you for sharing these helpful libraries.
RecordBuilder seems interesting library.
Hi Siva. I have seen your IntelliJ Session hosted by Mala Gupta (very, very good presentation by the way) and there you have used Spring Projections to create Dtos, instead of using MapStruct. Would you still recommend Spring Projections instead of MapStruct on enterprise applications development? Thanks for the video.
By using Spring Projection you can load only the columns you need. But using MapStruct you load entire entity first and then map the required properties to a DTO. This may result in loading unnecessary data.
So, I would recommend to use either interface-based projections or class-based projections to load only the required data from database. An important thing to consider is, we can't load nested objects while using class-based projections, but it is possible with interface-based projections.
@@sivalabsThank you very much, Siva, for this explanation.
Regarding MapStuct, does it support expression/ conditional kind of conversion?
Like suppose, I have a wrapper class Boolean in Entity. But I want to pass primitive boolean to DTO. Expression will be
flag == null ? false : true
flag is wrapper Boolean class in Entity.
Yes, it checks for null and assign the correct value as follows:
boolean active = false;
if ( user.active() != null ) {
active = user.active();
}
UserDTO userDTO = new UserDTO( id, fullName, emailAddress, active );