To map a DTO that has an attribute of type EnumSet:
EnumSet routeMapRange
The mapping implementation generated by MapStruct will produce uncompileable code like the following:
dto.setRouteMapRange( new EnumSet( entity.getRouteMapRange() ) );
This does not compile as EnumSet simply does not have the constructor needed.
Instead something like the following would work:
dto.setRouteMapRange(EnumSet.copyOf(entity.getRouteMapRange()));
As pointed out from Andreas Gudian a viable work-around is to define a protected copy() method inside the abstract mapper that MapStruct will use:
EnumSet copy(EnumSet transportRanges) { return ... }
As EnumSet is part of java language a native support for mapping it may be considered.
To map a DTO that has an attribute of type EnumSet:
EnumSet routeMapRange
The mapping implementation generated by MapStruct will produce uncompileable code like the following:
dto.setRouteMapRange( new EnumSet( entity.getRouteMapRange() ) );
This does not compile as EnumSet simply does not have the constructor needed.
Instead something like the following would work:
dto.setRouteMapRange(EnumSet.copyOf(entity.getRouteMapRange()));
As pointed out from Andreas Gudian a viable work-around is to define a protected copy() method inside the abstract mapper that MapStruct will use:
EnumSet copy(EnumSet transportRanges) { return ... }
As EnumSet is part of java language a native support for mapping it may be considered.