尝试使用@Data和@BuilderMap嵌套对象时,mapStruct抛出以下错误:未找到目标类型中属性“profile”的读访问器。
@Mapper(componentModel = "spring")
public interface AuthMapper {
// only for testing mapping is working
@Mapping(target = "profile.organization", source = "organization")
RequestCreateOktaUser toEntity(Integer organization);
// only for testing mapping is working
@Mapping(target = "profile.login", source = "request.profile.email")
RequestCreateOktaUser toEntity(RequestMobilePreRegisterLocation.User request);
// Throw error "No read accessor found for property "profile" in target type" at compile time
@Mapping(target = "profile.organization", source = "organization")
@Mapping(target = "profile.login", source = "request.profile.email")
RequestCreateOktaUser toEntity(RequestMobilePreRegisterLocation.User request, Integer organization);
}
使用Lombok简化模型以简化
x一个一个一个一个x一个一个二个x
前两个Map按预期工作,但在尝试合并这两个Map时,在编译时引发以下错误:“未找到目标类型中属性“profile”的读访问器。”
如果有人能在这件事上帮助我,我将非常感激。
多谢了
乔纳森。
2条答案
按热度按时间ddarikpa1#
解决方案:
sd2nnvve2#
我们可以添加另一个Map器,比如
ProfileMapper
,而不是忽略构建器,然后在“父Map器”(例如UserMapper
)中,您可以像这样使用Map器注解