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

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