Mapping two enums with different constant name

In this post under MapStruct I will show with example how to map two enums having different constant name. For our example lets say you have to map below enum Day package package12; public enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY; } to below enum Week package package12; public enum Week {…… Continue reading Mapping two enums with different constant name

Mapping two enums with same constant name

In this post under MapStruct, I will show with example how to map between two enums both having same constant name. For our example, I will use the below two enums ProcessStatus package package11; public enum ProcessStatus { RUNNING, PAUSE, CANCELLED, SHUTDOWN; } DisplayStatus package package11; public enum DisplayStatus { RUNNING, PAUSE, CANCELLED, SHUTDOWN; }…… Continue reading Mapping two enums with same constant name

Mapping flat objects to hierarchical objects

In the previous post under MapStruct I showed how to map hierarchial objects to flat objects. In this post, I will show the reverse i.e., how to map flat objects to hierarchical objects. We are assuming the property names on source and destination objects are same. For our example I will use the below model…… Continue reading Mapping flat objects to hierarchical objects

Mapping hierarchical objects to flat objects

In this post under MapStruct, I will show with example how to map hierarchical objects properties to flat object. In all my previous posts under MapStruct, the source object didn’t compose another object. In other words, there was no object hierarchy. In this post I will use a source object which has a hierarchy as…… Continue reading Mapping hierarchical objects to flat objects

Mapping to existing bean instances

In this post under MapStruct, I will explain with example how to map attributes from source object to attributes of another existing object. In all my previous post under MapStruct, when mapping attributes from source object to destination object, the Mapper framework used to create the destination object before mapping. But there may be scenarios…… Continue reading Mapping to existing bean instances

Mapping between objects with default value

In this post under MapStruct, I will show with example how to map two objects with default value. Let me further elaborate the requirement. We have “Student” class and we have to map the instance of “Student” class to an instance of “StudentDTO” class. During mapping if the value of “className” attribute in “Student” class…… Continue reading Mapping between objects with default value

Mapping from multiple objects to one destination object

In this post under MapStruct, I will explain with example how to map attributes from multiple objects to attributes of one single destination object. For our example I will two source class as shown below Person package package4; public class Person { private int id; private String name; private int age; private char sex; //Removed…… Continue reading Mapping from multiple objects to one destination object

Skipping mapping of particular attribute

In this post under MapStruct, I will show with example how to configure MapStruct to skip particular attribute mapping from source to destination. For our example I will use the below pojo classes as shown below Student package package3; public class Student { private int id; private String name; private String className; public int getId()…… Continue reading Skipping mapping of particular attribute