I am trying to use MapStruct for a structure similar to the following:
Source:
public class ClassSource{
private int id;
private String name;
private String numT;
private List<CustAddress> addresses = null;
private Person person;
}
public class CustAddress implements Serializable {
@JsonProperty("postalCode")
private String postalCode;
}
public class Person implements Serializable {
@JsonProperty("jobTitle")
private String jobTitle;
}
Destination :
public class ClassDestination {
private int id;
private String name;
private String numT;
private List<CustAddress> addresses = null;
}
public class CustAddress implements Serializable {
@JsonProperty("zipCode")
private String zipCode;
}
public class Person implements Serializable {
@JsonProperty("workTitle")
private String workTitle;
}
want to achieve the below mapping from Address list postalcode to destination address list zipcode and Person jobTitle on the subclass to target Person workTitle
public interface PersonMapper {
@Mapping(source = "addresses.postalCode", target = "addresses.zipCode")
@Mapping(source = "person.jobTitle", target = "person.workTitle")
ClassDestination map(ClassSource source);
The above @mapping not referring the subclass properly from source to destination.. it's throwing exceptions