mapstruct / mapstruct/mapstruct

Mapstruct doesn't use custom enum mapper

Open
#3,038 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
7.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Expected behavior
public interface CarMapper {

  CarDto carToCarDto(Car car);

  CarDtoEnum from(CarEnum carEnum);
}

should generate something like:

public class CarMapperImpl implements CarMapper {
  @Override
  public CarDto carToCarDto(Car car) {
     ...
      carDto.setCarDtoEnum(from(car.getCarEnum()));
   }
}
Actual behavior
public class CarMapperImpl implements CarMapper {
  @Override
  public CarDto carToCarDto(Car car) {
     ...
      carDto.setCarDtoEnum(Enum.valueOf(CarDtoEnum.class, car.getCarEnum()));
   }
}
Steps to reproduce the problem

see above description.

MapStruct Version

1.5.2.Final

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the CarMapper, Car, CarDto, CarEnum, and CarDtoEnum types shown in the report, then inspect the generated CarMapperImpl. Trace why enum mapping selects Enum.valueOf instead of the declared from(CarEnum) method; done when the generated mapper invokes that custom method.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.