MapStruct 1.4.0.CR1 released

I’m very happy to announce the first candidate release of MapStruct 1.4!

The CR1 release mostly provides bug fixes and other smaller improvements since the Beta 3, So what did we tackle in 1.4.0.RC1

  • Support for using a custom exception for an unexpected value mapping
  • Fix various bugs with generics and constructor mapping
  • Various small enhancements around error messages

8 issues were fixed for this release.

Thanks to our MapStruct community for being vigilant. The MapStruct authors: Filip Hrisafov, Christian Bandowski, Andrei Arlou and Sjaak Derksen.

Thank you everyone for all your hard work!

Support for using a custom exception for an unexpected value mapping

In this release we added support for using custom exceptions for unexpected value mappings

e.g.

public class CustomIllegalArgumentException extends RuntimeException {

    public CustomIllegalArgumentException(String message) {
        super(message);
    }
}

public enum OrderType {

    RETAIL, STANDARD, NORMAL
}

public enum ExternalOrderType {

    RETAIL, STANDARD, NORMAL
}

@Mapper
public interface OrderTypeMapperMapper {
    
    @EnumMapping(unexpectedValueMappingException = CustomIllegalArgumentException.class)
    ExternalOrderType map(OrderType orderType);
}

Will generate the following mapper:

public OrderTypeMapperImpl implements OrderTypeMapper {

    @Override
    public ExternalOrderType map(OrderType orderType) {
        if ( orderType == null ) {
            return null;
        }

        ExternalOrderType externalOrderType;

        switch ( orderType ) {
            case STANDARD: externalOrderType = ExternalOrderType.STANDARD;
            break;
            case NORMAL: externalOrderType = ExternalOrderType.NORMAL;
            break;
            case RETAIL: externalOrderType = ExternalOrderType.RETAIL;
            break;
            default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + orderType );
        }

        return externalOrderType;
    }
}

When will we release 1.4 Final?

We will wait for few weeks to get some feedback from the community and then do the final release for 1.4. We don’t expect major issues, since we have already received good feedback and ironed out the problems that we’ve had.

Download

This concludes our tour through MapStruct 1.4 CR1. If you’d like to try out the features described above, you can fetch the new release from Maven Central using the following GAV coordinates:

Alternatively, you can get ZIP and TAR.GZ distribution bundles - containing all the JARs, documentation etc. - from GitHub.

If you run into any trouble or would like to report a bug, feature request or similar, use the following channels to get in touch:

comments powered by Disqus