Reputation: 605
@Mapping(target = "content.shortText", qualifiedByName = "shortText")
@Mapping(target = "content.longText", qualifiedByName = "longText")
EntityDto mapToDto(Entity entity, String shortText, String longText);
I want to map second und third parameter in the @mappings as the source , but it never works.
If I do mapToDto(myEntity, "Hello", "WorldLong")
Hello should be mapped to target = "content.shortText"
and WorldLong to target = "content.longText"
but it does not work
Upvotes: 1
Views: 2960
Reputation: 126
qualifiedByName is used to call a method annotated with @Named. You should use the source parameter.
@Mapping(target = "content.shortText", source= "shortText")
@Mapping(target = "content.longText", source= "longText")
EntityDto mapToDto(Entity entity, String shortText, String longText);
You can read more in the documentation. Here is an example from the page:
@Mapper
public interface AddressMapper {
@Mapping(target = "description", source = "person.description")
@Mapping(target = "houseNumber", source = "hn")
DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Integer hn);
}
Upvotes: 2