我的相关课程:
package net.gencat.transversal.espaidoc.domain.model.reference;
import java.util.UUID;
import lombok.Getter;
@Getter
public class ReferenceId {
private final UUID id;
private ReferenceId(UUID id) {
validate(id);
this.id = id;
}
public static ReferenceId of(UUID id) {
return new ReferenceId(id);
}
private static void validate(UUID id) {
if (id == null) {
throw new IllegalArgumentException("Value cannot be null or empty");
}
}
}
如你所见,我的工厂方法是
of(UUID id)
。
当我尝试创建与
ReferenceId
类相关的映射器时,我得到:
ReferenceId 没有可访问的构造函数。
我怎样才能指示mapstruct使用
of(...
工厂方法而不是...?
AFAIK Mapstruct 至少需要一个公共非参数 c'tor 或任何其他,用
@Default
或工厂类注释。
C'tor only
private
无法工作,因为 Mapstruct 创建的映射器类必须实例化目标类的对象。
无论如何,我看不出使用
of()
或公开 c'tor ReferenceId(UUID id)
有什么区别。