Passing the target type to custom mapper

In previous post under MapStruct, I showed how to create a custom mapper method and how MapStruct framework calls it. For recap,1) sometimes we cannot depend on the mapping method created by MapStruct. So we create our own custom mapper method which takes care of mapping one object properties to another object properties.2) We instruct…… Continue reading Passing the target type to custom mapper

Calling mapper interface method from another mapper interface code

In this post under MapStruct, I will show with example how to call one mapper interface method from another mapper interface code. For our example I will create “Address” pojo class that will be shared by “Student” and “Person” pojo class as shown below. Address package package31; public class Address { private String addressLine1; private…… Continue reading Calling mapper interface method from another mapper interface code

Using @ObjectFactory annotation to create target objects

In this post under MapStruct, I will explain with example the purpose of “@ObjectFactory” annotation. Till now in all my previous post, I have shown you that MapStruct uses constructor and builder method to create target objects. We can also create an object using factory methods. To instruct MapStruct to stop using constructor, buider method…… Continue reading Using @ObjectFactory annotation to create target objects

Adding custom mapping method to Mapper interface

In this post under MapStruct, I will show with example how to add custom mapping methods if the out of the box generated mapping methods aren’t sufficient. For our example I will have the following pojo classes Person package package29; public class Person { private int id; private String name; private Address address; //Removed getter…… Continue reading Adding custom mapping method to Mapper interface

Using source object in expressions

In this post under MapStruct, I will show with example, how to use source object in our expressions. For our example, lets say we have to map “Student” object to “StudentDTO” object. Below are their class structures Student package package25; public class Student { private int id; private String firstName; private String lastName; //Removed the…… Continue reading Using source object in expressions

Mapping between objects with expressions

In this post under MapStruct, I will show with example how to add expressions in “@Mapping” annotation. For our example we will use the below classes Student package package24; import java.util.Date; public class Student { private int id; private String name; //Removed getter, setter, and toString for brevity } StudentDTO package package24; import java.util.Date; public…… Continue reading Mapping between objects with expressions

Mapping between objects with default and constant date value

In this post under MapStruct, I will show with example how to map a date as default and constant value. Below is the source class Student package package23; import java.util.Date; public class Student { private int id; private String name; //Removed getter, setter, and toString for brevity } The “Student” class has one field named…… Continue reading Mapping between objects with default and constant date value