【发布时间】:2021-06-22 01:05:26
【问题描述】:
这是我的映射器:
@Mapper
public interface ProductMapper {
ProductClassification toProductClassification(ProductTypes pisType);
}
ProductTypes 和 ProductClassification 是枚举。我希望它在无法映射枚举时抛出异常,但出现编译器错误:
The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via adding additional mappings: EXTERNAL, UNKNOWN.
我尝试了@ValueMappings注解,但只能将其配置为将值设置为null,这是不够的:
@ValueMappings({
@ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL)
})
配置 MapStruct 映射器以在无法映射枚举常量时抛出异常的正确方法是什么?
【问题讨论】: