linpeilie / mapstruct-plus

MapStruct Plus is an enhancement to the MapStruct framework. It can automatically generate the transformation operation between two classes through an annotation, omitting the operation of defining the interface of MapStruct, makes Java type conversion easy and elegant.
https://mapstruct.plus/
Apache License 2.0
263 stars 20 forks source link

使用convert(source, target) 方法的时候,source对象里空的属性忽略,不覆盖target对象的属性问题 #79

Closed cloudlessa closed 3 months ago

cloudlessa commented 5 months ago

1.AutoMapping注解 表字段很多不方便,也不想全局修改 2.MapperConfig注解 配置自定义的NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default NullValuePropertyMappingStrategy.IGNORE; 这个也不太方便,不想全局修改。只是特殊情况下会使用到这个source的属性为空的时候,保留target的原来的属性 目前只找到这两个方法,还有其他更好的方法吗?

能提供一个类似的方法convert(source, target, strategy) strategy类,自定义转换过程中的配置。 或者其他方法也行。

linpeilie commented 5 months ago

下个版本会在 AutoMapper 中增加 nullValuePropertyMappingStrategy,就可以针对单个类进行配置了,已经加好了,正在测试阶段。

strategy这个加不了,因为 MapStruct 的原理是在编译阶段生成转换代码,所以执行的时候,转换逻辑是固定的,不能配置。

cloudlessa commented 5 months ago

下个版本 AutoMappernullValuePropertyMappingStrategy是可以针对source或者target都可以进行配置的吧?期待早点上线。

linpeilie commented 5 months ago

下个版本 AutoMappernullValuePropertyMappingStrategy是可以针对source或者target都可以进行配置的吧?期待早点上线。

可以的,支持在 AutoMapping 上面配置,这次把 MapStruct 注解中所有支持的配置都加上了,所以需要测试的有点多,我尽快

github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 3 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.