Package org.mapstruct

Annotation Type Condition

  • @Target(METHOD)
    public @interface Condition
    This annotation marks a method as a presence check method to check check for presence in beans.

    By default bean properties are checked against null or using a presence check method in the source bean. If a presence check method is available then it will be used instead.

    Presence check methods have to return boolean. The following parameters are accepted for the presence check methods:

    • The parameter with the value of the source property. e.g. the value given by calling getName() for the name property of the source bean
    • The mapping source parameter
    • @Context parameter
    Note: The usage of this annotation is mandatory for a method to be considered as a presence check method.
     public class PresenceCheckUtils {
       public static boolean isNotEmpty(String value) {
          return value != null && !value.isEmpty();
     @Mapper(uses = PresenceCheckUtils.class)
     public interface MovieMapper {
         MovieDto map(Movie movie);
    The following implementation of MovieMapper will be generated:
     public class MovieMapperImpl implements MovieMapper {
         public MovieDto map(Movie movie) {
             if ( movie == null ) {
                 return null;
             MovieDto movieDto = new MovieDto();
             if ( PresenceCheckUtils.isNotEmpty( movie.getTitle() ) ) {
                 movieDto.setTitle( movie.getTitle() );
             return movieDto;
    Filip Hrisafov