Created
March 7, 2024 01:25
-
-
Save msbaek/bb8329640971f7eb72ccd32df3846013 to your computer and use it in GitHub Desktop.
MapStruct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mapstruct | |
annotationProcessor "org.mapstruct:mapstruct-processor:$mapstructVersion" | |
implementation "org.mapstruct:mapstruct:$mapstructVersion" | |
[For Java Developers: Forget BeanUtils and Trade for Performance and Code Simplicity by MapStruct | by Malvin Lok | Feb, 2024 | Medium](https://medium.com/@malvin.lok/for-java-developers-forget-beanutils-and-trade-for-performance-and-code-simplicity-by-mapstruct-b8934c830094) | |
@Data | |
@Builder | |
@AllArgsConstructor | |
@NoArgsConstructor | |
public class ProductEntity { | |
private UUID id; | |
private String name; | |
private long number; | |
private UUID userId; | |
private String dateStr; | |
private String buyerIdStr; | |
} | |
@Data | |
@Builder | |
@AllArgsConstructor | |
@NoArgsConstructor | |
public class ProductVO { | |
private UUID id; | |
private String name; | |
private long number; | |
private UUID ownerId; | |
private Date date; | |
private UUID buyerId; | |
} | |
@Mapper(imports = UUID.class) | |
public interface ProductMapper { | |
ProductMapper INSTANCE = Mappers.getMapper(ProductMapper.class); | |
@Mapping(target = "ownerId", source = "userId") | |
@Mapping(target = "date", source = "dateStr", dateFormat = "yyyy-MM-dd") | |
@Mapping(target = "buyerId", source = "buyerIdStr", defaultExpression = "java( UUID.fromString(productEntity.getBuyerIdStr()) )") | |
ProductVO entity2VO(ProductEntity productEntity); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment