Skip to content

Make MapStruct generate compileable mapping code for attributes of type EnumSet #732

Description

@joedoehh

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions