MapStruct не использует повторно уже определенные картографы.JAVA

Программисты JAVA общаются здесь
Anonymous
MapStruct не использует повторно уже определенные картографы.

Сообщение Anonymous »

У меня есть следующие картографы:

Код: Выделить всё

@Mapper(uses = { IItemMapper.class, IChainMapper.class, ICountryMapper.class, IForecastFeatureMapper.class })
public interface IForecastMapper {

ForecastModel fromForecastDTOToForecastModel(ForecastDTO dto);
}

@Mapper
public interface ICountryMapper {

@Mapping(target = "name", ignore = true)
@Mapping(target = "acronym", ignore = true)
@Mapping(target = "status", ignore = true)
CountryModel fromForecastDTOToCountryModel(ForecastDTO forecastDTO);
}
Учитывая, что объект ForecastModel построен, как показано ниже:

Код: Выделить всё

@Entity
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "forecast")
public class ForecastModel implements Serializable {

@Serial private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
@UuidGenerator
@com.enterprise.b2b.api.service.common.hibernate.constraint.UUID
private UUID id;

@NotNull
@ManyToOne
@JoinColumn(name = "country_id", referencedColumnName = "id", nullable = false)
private CountryModel countryId;
}
Разве MapStruct не должен использовать метод fromForecastDTOToCountryModel из ICountryMapper внутри метода fromForecastDTOToForecastModel из IForecastMapper?Вместо этого MapStruct генерирует защищенный метод внутри реализации следующим образом:

Код: Выделить всё

protected CountryModel forecastDTOToCountryModel(ForecastDTO forecastDTO) {
if ( forecastDTO == null ) {
return null;
}

CountryModel.CountryModelBuilder countryModel = CountryModel.builder();

if ( forecastDTO.getCountryId() != null ) {
countryModel.id( UUID.fromString( forecastDTO.getCountryId() ) );
}

return countryModel.build();
}
Даже когда я пытаюсь принудительно использовать аннотацию @Mapping, MapStruct все равно генерирует метод, например:

Код: Выделить всё

@Mapper(uses = { IItemMapper.class, IChainMapper.class, ICountryMapper.class, IForecastFeatureMapper.class }, imports = Mappers.class)
public interface IForecastMapper {

@Mapping(target = "countryId", expression = "java(Mappers.getMapper(ICountryMapper.class).fromForecastDTOToCountryModel(dto))")
ForecastModel fromForecastDTOToForecastModel(ForecastDTO dto);
}
mapStruct просто игнорирует выражение и генерирует метод. Я использую MapStruct 1.6.2.
Есть мысли?

Подробнее здесь: https://stackoverflow.com/questions/790 ... ed-mappers

Вернуться в «JAVA»