Mapping between objects with constant value

In this post under MapStruct, I will show with example how to map between objects with constant value. Lets say you have to map “Student” object to “StudentDTO” object. Below is the class structure for your reference. Student package package22; public class Student { private int id; private String name; //removed getter, setter, and toString…… Continue reading Mapping between objects with constant value

InheritInverseConfiguration annotation example

In this post under MapStruct I will explain with example the purpose of “InheritInverseConfiguration” annotation. Lets say you have Mapper interface that has declared a method whose purpose is to map properties of “Student” to properties of “StudentDTO”. You have used “@Mapping” annotation on the method to tell MapStruct how to map property that differ…… Continue reading InheritInverseConfiguration annotation example

Adding callback methods in java interface class used as Mapper interface

In previous post under MapStruct I showed with example how to add callback methods in abstract class used as Mapper interface. In this post I will show with example how to add callback methods in interface used as Mapper Interface. For our example I will take the below Pojo class Student package package19; public class…… Continue reading Adding callback methods in java interface class used as Mapper interface

Adding callback methods in abstract class used as Mapper interface

In this post under MapStruct, I will show with example how to add callback methods which will be executed before and after mapping, in abstract class used as Mapper interface. We use two annotations “@BeforeMapping” and “@AfterMapping” to annotate methods which will be called before and after mapping. Lets say for example I have to…… Continue reading Adding callback methods in abstract class used as Mapper interface

MappingConstants.ANY_REMAINING

In this post under MapStruct, I will explain with example the purpose of “MappingConstants.ANY_REMAINING” enum constant. This enum constant is basically used when mapping source enum constant to destination enum constant. This enum constant is used in mapping interface to represent enum constants which don’t have explicit “@ValueMapping” annotation. Let me explain with an example…… Continue reading MappingConstants.ANY_REMAINING

MappingConstants.THROW_EXCEPTION example

In this post under MapStruct, I will explain with example the purpose of enum “MappingConstants.THROW_EXCEPTION”. This enum is mainly used when mapping source enum constant to destination enum constant. If you want to throw an exception for some source enum constant. We can use this enum constant. Below is the example showing the usage. Lets…… Continue reading MappingConstants.THROW_EXCEPTION example

MappingConstants.ANY_UNMAPPED example

In this post under MapStruct, I will explain with example the purpose of MappingConstants.ANY_UNMAPPED enum. This enum is used when mapping two enums with different constant names. It indicates MapStruct that any unmapped enum constant (i.e., source enum constant without any explicit mapping) must be mapped to a particular target enum constant. The specific target…… Continue reading MappingConstants.ANY_UNMAPPED example