I tried to follow the approach mentioned in this page, but could not concat name and surname fields.
Here is what I tried:
@Mapper(componentModel = "spring")
public interface PostDtoMapper {
Post toEntity(PostDto source);
@Mapping(ignore = true, source = "user", target = "user")
@Mapping( target = "userName", source = "user.firstName")
PostDto toDto(Post destination);
@AfterMapping
default void toDto(@MappingTarget PostDto postDto, Post post) {
User user = post.getUser();
postDto.setUserName(user.getFirstName() + " " + user.getLastName());
}
}
But it only gives the firstName
value. Any idea?