MapStruct 1.6.0.RC1 is out

I am very happy to announce the first (and last) release candidate of MapStruct 1.6. We are looking into release the final version of 1.6 in the next two weeks.

This release provides mostly bug fixes since 1.6.0.Beta2.

This release contains 2 breaking changes, have a look at them when upgrading

We’d like to thank our new supporters:

And of course thanks to our previous supporters:

If you’d like to join this list and donate to the project MapStruct is accepting donations through Open Collective or GitHub.

Altogether, not less than 8 issues were fixed for this release.

This would not have been possible without our fantastic community of contributors:

Thank you everyone for all your hard work!

Enough of the pep talk, let’s take a closer look at the breaking changes:

Revert BeanMapping#ignoreByDefault interaction with unmappedSourcePolicy

In 1.5.0 we started applying the BeanMapping#ignoreByDefault to source properties as well. However, we’ve decided that this was not the right approach, and we are reverting this change. The BeanMapping#ignoreByDefault should only be applied to target properties and not to source properties. Source properties are ignored anyway, the BeanMapping#unmappedSourcePolicy should be used to control what should happen with unmapped source policy.

Presence checks for source parameters

In the 1.6 beta releases we added support for presence checks on source parameters.

This means that even if you want to map a source parameter directly to some target property the new @SourceParameterCondition or @Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS) should be used.

e.g.

If we had the following in 1.5:

@Mapper
public interface OrderMapper {

    @Mapping(source = "dto", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder")
    Order map(OrderDTO dto);

    @Condition
    @Named("mapCustomerFromOrder")
    default boolean mapCustomerFromOrder(OrderDTO dto) {
        return dto != null && dto.getCustomerName() != null;
    }

}

Then MapStruct would generate

public class OrderMapperImpl implements OrderMapper {

    @Override
    public Order map(OrderDTO dto) {
        if ( dto == null ) {
            return null;
        }

        Order order = new Order();

        if ( mapCustomerFromOrder( dto ) ) {
            order.setCustomer( orderDtoToCustomer( orderDTO ) );
        }

        return order;
    }
}

In order for the same to be generated in 1.6, the mapper needs to look like this:

@Mapper
public interface OrderMapper {

    @Mapping(source = "dto", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder")
    Order map(OrderDTO dto);

    @SourceParameterCondition
    @Named("mapCustomerFromOrder")
    default boolean mapCustomerFromOrder(OrderDTO dto) {
        return dto != null && dto.getCustomerName() != null;
    }

}

Download

This concludes our tour through MapStruct 1.6 RC1. 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