In quarkus project I try to map DataSyncConfigurationMapping and DataSyncConfigurationMappingEntity with using MapStruct 1.5.5.Final version, except columnNames/columnNameList fields other field types matches and when tested the other field mappings works smoothly. What i have missed, any helps?
public class DataSyncConfigurationMappingEntity{
private Long id;
private String columnNames;
private String oldValue;
private String newValue;
private DataSyncConfigurationEntity dataSyncConfiguration;
}
public class DataSyncConfigurationMapping{
private Long id;
private List<String> columnNameList;
private String oldValue;
private String newValue;
private DataSyncConfiguration dataSyncConfiguration;
}
public class DataSyncConfigurationEntity{
private Long id;
private String name;
private String fileName;
private String sqlStatement;
private String columnNames;
private String cron;
}
public class DataSyncConfiguration{
private Long id;
private String name;
private String fileName;
private String sqlStatement;
private List<String> columnNameList;
private String cron;
}
@Mapper(componentModel = "jakarta", uses = {DataSyncConfigurationMapper.class})
public interface DataSyncConfigurationMappingMapper {
@Mapping(source = "dataSyncConfiguration.columnNames", target = "dataSyncConfiguration.columnNameList",
qualifiedByName = "stringToListConverter")
DataSyncConfigurationMapping entityToPojo(DataSyncConfigurationMappingEntity entity);
@Mapping(source = "dataSyncConfiguration.columnNameList", target = "dataSyncConfiguration.columnNames",
qualifiedByName = "listToStringConverter")
DataSyncConfigurationMappingEntity pojoToEntity(DataSyncConfigurationMapping pojo);
@Named("stringToListConverter")
default List<String> map(String value) {
return stringToList(value);
}
@Named("listToStringConverter")
default String map(List<String> list) {
return listToString(list);
}
}
@Mapper(componentModel = "jakarta")
public interface DataSyncConfigurationMapper {
@Mapping(source = "columnNames", target = "columnNameList")
DataSyncConfiguration entityToPojo(DataSyncConfigurationEntity entity);
@Mapping(source = "columnNameList", target = "columnNames")
DataSyncConfigurationEntity pojoToEntity(DataSyncConfiguration pojo);
default List<String> map(String value){
return stringToList(value);
}
default String map(List<String> list){
return listToString(list);
}
}
@ApplicationScoped
public class MapperUtils {
public static List<String> stringToList(String columnNames) {
if (columnNames == null) {
return null;
} return Arrays.asList(columnNames.split(","));
}
public static String listToString(List<String> list) {
if (list == null) {
return null;
}
return String.join(",", list);
}
}
@QuarkusTest
public class DataSyncConfigurationMappingMapperTest {
@Inject
DataSyncConfigurationMappingMapper dataSyncConfigurationMappingMapper;
@Test
public void testEntityToPojo() {
DataSyncConfigurationMappingEntity entity = new DataSyncConfigurationMappingEntity();
entity.setColumnNames("column1,column2,column3");
entity.setOldValue("name");
DataSyncConfigurationEntity dataSyncConfigurationEntity = new DataSyncConfigurationEntity();
dataSyncConfigurationEntity.setName("sss");
dataSyncConfigurationEntity.setColumnNames("a1,b2,c3");
entity.setDataSyncConfiguration(dataSyncConfigurationEntity);
DataSyncConfigurationMapping pojo = dataSyncConfigurationMappingMapper.entityToPojo(entity);
assertEquals(entity.getId(), pojo.getId());
assertEquals(Arrays.asList(entity.getColumnNames().split(",")), pojo.getColumnNameList());
assertNotNull(pojo.getDataSyncConfiguration());
assertEquals(dataSyncConfigurationEntity.getName(), pojo.getDataSyncConfiguration().getName());
assertEquals(Arrays.asList(dataSyncConfigurationEntity.getColumnNames().split(",")), pojo.getDataSyncConfiguration().getColumnNameList());
}
}
Like i mention on my code i tried to use stringToListConverter and listToStringConverter named methods to convert, but couldn t accomplished for this fields.