Skip to content
Advertisement

How to convert an interface with MapStruct?

I made some research in the mapStruct documentation but did not find or understood what I could do to achieve this: the conversation of an entity containing an interface to a flat DTO object.

Here the entity with the attribute:

JavaScript

Here the DTO:

JavaScript

We try this mapping :

JavaScript

With a classic mapping, mapStruct generates an error (IUser is abstract; cannot be instantiated).

Any idea ? Thank you.

Advertisement

Answer

Not sure its the best way to do it…

But we used @AfterMapping to create manually in default method the object to implement on interface.

We had to delete @InheritInverseConfiguration for reverse operation.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement