Mapping of Enums via @Mapping is removed. Please use @ValueMapping instead!

Problem: In Java when you are using Mapstruct and it returns next error:

Mapping of Enums via @Mapping is removed. Please use @ValueMapping instead!

Solution: The problem is that you are using @Mapping and you have to use @ValueMapping when you are mapping Enums.

Example:

//Correctly mapping between enums

@ValueMapping(source="value1_typeTwo", target="value1_typeOne")
@ValueMapping(source="value2_typeTwo", target="value2_typeOne")
@ValueMapping(source="value3_typeTwo", target="value3_typeOne")
TypeOneEnum typeTwoEnumToTypeOneEnum(TypeTwoEnum typeTwoEnum)

For more interesting tutorials & guides just check themĀ HERE.

Leave a Reply

Your email address will not be published. Required fields are marked *