public class User {
private Set<Role> roles;
}
public class Role {
private String name;
}
public class UserViewModel {
private Set<String> roles;
}
@Mapper(uses = "RoleMapper.class")
public interface UserMapper {
UserViewModel userToUserViewModel(User user);
}
@Mapper
public abstract class RoleMapper {
public String roleToRoleName(Role role) {
return role.getName();
}
}
--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Generally, we want MapStruct to help people solve the 80 - 90 percent of their mapping problems, and allow them to fill in the gaps themselves manually, with plain Java... :-)Hi George,for that particular case (picking a property of a collection element type), we don't have an annotation. For the use case you demonstrate, the suggested solution is exactly the one you chose: add the method yourself.Andreas
2015-10-28 17:10 GMT+01:00 George Pai <g...m>:
Checking to see if I'm overlooking something. In my User I have a set of Roles, however in my User view model I have a set of Strings that are the role identifiers. This is what I basically have now (minus irrelevant and implicit code)public class User {
private Set<Role> roles;
}
public class Role {
private String name;
}
public class UserViewModel {
private Set<String> roles;
}
@Mapper(uses = "RoleMapper.class")
public interface UserMapper {
UserViewModel userToUserViewModel(User user);
}
@Mapper
public abstract class RoleMapper {
public String roleToRoleName(Role role) {
return role.getName();
}
}
Is there an annotation or something I can use instead of explicitly writing out the code? This is more for curiosity sake than anything else (since the implementation is trivial, and probably refactors better than any annotation would)
--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-users+unsubscribe@googlegroups.com.
To post to this group, send email to mapstruct-users@googlegroups.com.