In this post under MapStruct, I will show with example how to pass context information to the mapping methods. For our example, I will have “Person” entity and map it to “PersonDTO” entity. Below is the class structure of “Person” class Person package package34; public class Person { private int id; private String name; private…… Continue reading Passing context information to mapping method
Tag: MapStruct
Using multiple source object in expressions
In previous posts under MapStruct, I introduced you guys to expressions and then I showed how we can use a source object in an expressions. Just to be thorough, in this post under MapStruct, I will show with example that we can refer multiple source objects in an expressions. For our example, we use below…… Continue reading Using multiple source object in expressions
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
Mapping beans that refer another bean as its properties
In all my previous posts under MapStruct, whenever I gave an example of MapStruct, I used a bean having only primitive data types and not user defined types. In this post, I will show with example how to do mapping of a bean which refers to another bean as its property. For our example I…… Continue reading Mapping beans that refer another bean as its properties
Using defaultExpressions
In this post under MapStruct, I will explain with example the purpose of “defaultExpressions”. Default expressions are the expressions that are executed with the source attribute is null. I have introduced you to expressions in MapStruct in previous posts. Till now we were using expressions without the source attribute. But in case of default expressions…… Continue reading Using defaultExpressions
Using decorator during mapping
In this post under MapStruct, I will show how to use decorator to implement pre and post mapping operations. For our example, we will use the “Student” and “StudentDTO” pojo classes. The class structure is as shown below Student package package26; public class Student { private int id; private String name; private String className; //Removed…… Continue reading Using decorator during mapping
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