Mapstruct mapping incorrect properties when one of them is supporting adder
还没有人认领这个 Issue。
评估
调研方向
从链接的 issue-4038 复现项目开始,检查针对 items、moreItems 和 setItems 属性生成的 RequestMapper.toDto 方法。将生成的映射与 issue 中的预期行为进行比较;完成标准是每个源属性都映射到对应的目标属性,并且仅对 items 使用 adder。
由索引模型根据 Issue 内容生成。
描述
Expected behavior
If I have 2 List mapped in a class with one of them having adder, then mapstruct should ideally make use adder for this property and setter for the other.
Actual behavior
Mapstruct is mapping both source proprties to this adder property, which is incorrect
@Value
@Builder
class RequestDto {
String name;
@Singular("addItem")
List<String> items;
List<String> moreItems;
Set<String> setItems;
}
@Value
@Builder
class RequestBean {
String name;
List<String> items;
List<String> moreItems;
Set<String> setItems;
}
@Mapper(config = CentralConfig.class)
interface RequestMapper {
RequestDto toDto(RequestBean requestBean);
}
// Generated Code
@Override
public RequestDto toDto(RequestBean requestBean) {
if ( requestBean == null ) {
return null;
}
RequestDto.RequestDtoBuilder requestDto = RequestDto.builder();
if ( prechecksSupport.isNotBlank( requestBean.getName() ) ) {
requestDto.name( requestBean.getName() );
}
if ( prechecksSupport.isNotEmpty( requestBean.getItems() ) ) {
for ( String item : requestBean.getItems() ) {
requestDto.addItem( item );
}
}
if ( prechecksSupport.isNotEmpty( requestBean.getMoreItems() ) ) {
for ( String moreItem : requestBean.getMoreItems() ) {
requestDto.addItem( moreItem );
}
}
return requestDto.build();
}
If we see here, moreItems and setItems are not mapped properly
Steps to reproduce the problem
https://github.com/altaiezior/mapstruct-issues/tree/master/issue-4038
MapStruct Version
Mapstruct 1.5.5
- 主要语言
- Java
- 星标
- 7.7k
- 派生
- 1.1k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mapstruct/mapstruct 的其他 Issue
-
bug test
难度 4/5 3-5 天 新手友好度 48/100
-
bug
难度 3/5 1-2 天 新手友好度 68/100
-
难度 4/5 3-5 天 新手友好度 68/100
-
bug JSpecify
-
难度 3/5 1-2 天 新手友好度 72/100
查看 mapstruct/mapstruct 的全部 Issue
相似的 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 65/100
inu-appcenter/memorIN-backend#288 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
frontend maui-pilot pilot-ask question
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
-
area/plugin
难度 2/5 1-3 小时 新手友好度 75/100
kestra-io/plugin-kestra#190 ·