错误尝试在映射中转换对象
我正在尝试将classDomain类转换为classentity,但是它不起作用,因为它在下面返回错误,我不知道该如何解决:
error: The return type List<DomainClass> is an abstract class or interface. Provide a non abstract / non interface result type or a factory method.
类dataDomainClass:
public class DataDomainClass{
private List<DomainClass> data;
}
class entityClass:
public class EntityClass {
private String codDist;
private String numF;
private String textJus;
private Boolean valResol;
}
convert mapper:
DataDomainClass map(EntityClass entity);
domainClass类包含与相同的字段EntityClass类。
提前致谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有明确的脱机实现。映射不支持映射从不可学到到峰值。 。这是针对原语的更通用的解决方案。
对于您的情况,最简单的解决方案是:
解决方案1:映射实体的自定义方法
生成的代码:
解决方案2:表达式
生成的代码:
更新:
也不支持非意识映射。在 iToser-to-non-titerable 。
案例反向映射的示例:
There is no clear out-of-box implementation. MapStruct does not support mapping from non-iterable to iterable. Workaround described in mapstruct-examples. This is more general solution for primitives.
For your case simplest solutions are:
Solution 1: custom method for mapping entity to List
Generated code:
Solution 2: Expression
Generated code:
UPDATE:
Iterable to non-iterable mapping also is not supported. Workaround for primitive types described at iterable-to-non-iterable.
Example of reverse mapping for your case:
映射无法将非意素类型映射到迭代中,尤其是嵌套集合不可绘制的映射。
以下是几种解决方案:
更改方法签名,因此输入和输出参数将是相同的类型(iTable或nor-Ableable),并在代码中进一步进行包装。这是最可取的解决方案
,您也可以在接口中创建默认方法以在此处进行包装:
因此,您没有调用自动生成的方法,而是调用默认方法
@后图
,但它仍然需要您自己实现包裹ept:您也可以使用
Extensions
如Eugene所指定的,但是最清洁的方法是使映射器尽可能简单(理想情况下,根本不应该有非自动化代码),并处理填充list&lt; domainClass&gt;
在代码中的其他地方。MapStruct can't map non-iterable type to iterable, especially mapping non-iterable to a nested collection.
Here's several solutions:
Change method signatures so input and output parameters will be the same type(iterable or non-iterable) and do the wrapping further in code. This is the most preferable solution
Also you can create default method in your interface to do the wrapping there:
So instead of calling auto-generated method you'll call default method
Or if you wanna hide all the wrapping inside MapStruct mapper you can use
@AfterMapping
, but it still will require you to implement the wrapping by yourselfUPD: You can also use
extensions
as Eugene specified, but the cleanest approach will be to keep mapper as simple as possible(ideally there should be no non-autogenerated code at all) and handle populatingList<DomainClass>
somewhere else in code.