MapStruct: Difference between BeanMapping and Mapping

Erric :

I have been going through the documentation of MapStruct and can't seem to figure out when the annotation @BeanMapping should be used. The documentation seems to extensively use just @Mapping for most cases as well. Could someone explain the use of @BeanMapping annotation? Perhaps with an example?

Filip :

The @Mapping annotation is one of the core annotation of MapStruct. It allows you to define mappings between properties that are not named the same. From the JavaDoc:

Configures the mapping of one bean attribute.

The @BeanMapping annotation is there to control the behaviour of the entire mapping method. You can use @BeanMapping to set the NullValueCheckStrategy for the entire mapping method. From the JavaDoc:

Configures the mapping between two bean types

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=150667&siteId=1