Have a Maapstruct mapping interface and DTO with various enums. I have two different enums both of the format:
public enum TxAccTypeDto {
FINANCE("Finance")
}
public enum TxStatusDto {
PENDING("Pending"),
}
public enum TxStatusDto {
PENDING("Pending"),
}
public enum ContactMethod {
TELEPHONE,
Issue I have is when converting from Entity fields of type String (not enum) how do I get the right enum used and matching on the Code (value in brackets)?
If used only one enum, then could use this:
default TxAccTypeDto toEnum(final String code) {
return Arrays.stream(TxAccTypeDto.values()).filter(
testEnum -> testEnum.getCode().equals(code))
.findFirst()
.orElse(null);
}
But it obviously does not know the enum to map to with param String code. Was hoping I could:
- just do toEntity(fromDto) and toDto(fromStringCode, forDtoTypeAndFile)
- only add code per type and not each source/target