I'm trying to map next structure(succesfully map in dozer, have some problems with mapstruct) list is absent in source, how can I get its first element in mapper? Target class:
@Data
public class FirstLvl {
protected List<SecondLvl> list;
@Data
public static class SecondLvl {
protected FirstLvl.SecondLvl.ThirdLvl thirdLvl;
@Data
public static class ThirdLvl {
protected FourthLvl fourthLvl;
}
}
}
@Data
public class FourthLvl {
protected FourthLvl.FithLvl fithLvl;
@Data
public static class FithLvl {
protected String str1;
protected String str2;
}
}
Source:
@Data
public class FirstLvlDTO {
protected FirstLvlDTO.SecondLvlDTO secondLvlDTO ;
@Data
public static class SecondLvlDTO {
protected FirstLvlDTO.SecondLvlDTO.ThirdLvlDTO thirdLvlDTO ;
@Data
public static class ThirdLvlDTO {
protected FourthLvlDTO fourthLvlDTO;
}
}
}
@Data
public class FourthLvlDTO {
protected String str1;
protected String str2;
}
Mapper and Object factory:
@Mapper(uses = { ObjectFactory.class })
public interface FirstLvlDTOtoFirstLvl {
@Mapping(target="list[0].thirdLvl.fourthLvl.fithLvl.str2", source="secondLvlDTO.thirdLvlDTO.fourthLvlDTO.str2")
FirstLvl toFirstLvl (FirstLvlDTO firstLvlDTO );
}
public class ObjectFactory {
public FirstLvl createFirstLvl() {
return new FirstLvl();
}
public FirstLvl.SecondLvl createFSLvl() {
return new FirstLvl.SecondLvl();
}
}
The problem is I don't know how to get first element of List([] notation is not used in mapstruct). I can add methods getlist0/setlist0 to class FirstLvl for simply returning first element of List(return list.get(0)) and use it in mapper like list0.thirdLvl.fourthLvl.fithLvl.str2, but I don't know is it good idea and is it possible to do it better List is absent in FirstLvlDTO (source), so I really can't understand how to map it and set this nested structure to first element of List