I'm new to mapstruct. I'm trying to map ItemInfo
to Item
object and the following are my classes.
public class ItemInfo {
private String itemOwner;
private String itemOwnerArea;
//getters and setters
}
Following is the class that I'm planing to convert to
public class Item {
private UserInfo owner;
// getters and setters.
}
UserInfo class (Note that it has two constructors)
public class UserInfo {
private final String username;
private final String area;
public UserInfo(String username, String area){
//set
}
public UserInfo(String info) {
//set
}
// getters only
}
I have created the mapper interface as below
@Mapper
public interface ItemMapper {
ItemMapper INSTANCE = Mappers.getMapper(ItemMapper.class);
@Mapping(source = "itemOwner", target = "owner.username")
@Mapping(source = "itemOwnerArea", target = "owner.area")
Item mapItemInfoToItem(ItemInfo itemInfo);
}
When I build this, I get the following error
Ambiguous constructors found for creating com.app.test.UserInfo. Either declare parameterless
constructor or annotate the default constructor with an annotation named @Default.
Can you guide me please?
Update.
As mentioned by @AnishB I added a default constructor but I get a different error
Property "username" has no write accessor in UserInfo for target name "owner.username".
Thanks