mapstruct v1.3.1FINAL: imports from static methods aren't generated

Viewed 2922

We are using mapstruct 1.3.1FINAL (in combination with lombok v1.18.4 if that matters) and the generated classes aren't compiling because the imports of the static methods used in expression mappings aren't generated. Any clues?

@Mapping(target = "value", expression = "java(ValueUtil.getValue(sourceValue))")

The generated code has compilation errors because the import of ValueUtil is missing :

request.setValue( ValueUtil.getValue(sourceValue) );
3 Answers

Finally i got it, tried out what Sjaak wrote.

@Mapper(imports = { ValueUtil.class })

The import made it. Will try out if Deepaks answer works as well.

Please try with fully qualified class name for ValueUtil I.e. packagename.ValueUtil. This will provide the context to mapstruct to locate the class.

you can add an import statement to the @Mapper annotation, precisely for such cases. Checkout the documentation.

Related