public class Source1 {
private String name; //srihari
private List<String> city_names; //city_names.add("hyderabad-india")
}
public class Soruce2 {
private String name;
private String city_name; //hyderabad-india
private List<String> technologies; //Arrays.asList("java","mapstruct")
}
public class Target {
private String name; // Result: srihari
private String city_names; // Result: hyderabad-india
private String technologies; // Result: java, mapstruct
}`
list has only one value means list.size()=1. If source1 name is empty then it has to take from source2. And target should contain all the fields even-though those are not available in one source
try:
@Mapper
public interface MyMapper{
// will map all other fields that you specify
@Mapping( target = "city_names", ignore = true )
@Mapping( target = "technologies", ignore = true )
Target map(Source1 s1, Soruce2 s2);
default map(Source1 s1, Soruce2 s2, @MappingTarget Target t) {
// do whatever you like with city_names and technologies
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With