mapstruct / mapstruct/mapstruct
Non-Null check on nested collection mapping
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 7.7k
- 派生
- 1.1k
- PR 合并指标
- 30 天内没有已合并 PR
描述
I have a set of classes like the following
ClassRoot, ClassA, ClassB
ClassRootDto, ClassADto, ClassBDto
where
ClassRoot has a list of ClassA, and ClassA has a list of ClassB
ClassRootDto has a list of ClassADto, and ClassADto has a list of ClassBDto
I tried to map a ClassRoot instance to a ClassRootDto instance
The list of ClassADto instances is explicit set to the field of ClassRootDto instance without any problem.
However, when set the list of ClassBDto to the field of a ClassADto instance, the generated code does a null check on the target field.
Why are there different null-check behaviors for different level of mappings?
My current solution:
Initialize an empty ClassBDto list in ClassADto field
My expectation
I expect there should be no null-check on target field when doing collection mapping
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现 issue 中描述的 ClassRoot、ClassA 和 ClassB 嵌套映射,然后检查为 ClassBDto collection 赋值的生成 mapper。将这段生成的代码与 ClassADto collection 的赋值进行比较,并确定 target null 检查是否应有所不同。当预期行为得到明确并由回归测试覆盖时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100