Questions tagged [mapstruct]

MapStruct is a code generator for creating efficient, type-safe bean-to-bean mappings in Java.

MapStruct generates bean mapping code at compile time by means of a JSR 269 annotation processor.
The generated code is fast (no reflection or byte code generation at runtime), type-safe (code is generated from typed, domain-specific interfaces) and dependency-free.

Source Code

1447 questions
9
votes
3 answers

Intellij + Ajc + Lombok/Mapstruct

I want to enable AspectJ compiler in my IntelliJ Idea as I have several aspects that I'd like to be woven during compile time. At the same time, I am using Lombok and Mapstruct in my codebase. Those 2 require additional annotations processing, that…
Ihor M.
  • 2,728
  • 3
  • 44
  • 70
9
votes
2 answers

Can I create a DeepCopy of an Java Object/Entity with Mapstruct?

I have a JPA entity (but this question is interesting in general) that consists of multiple child classes (aggregation). I need to create a new entry in the DB that is 90% identical to the existing one (a few business values and of course the IDs…
KFleischer
  • 942
  • 2
  • 11
  • 33
9
votes
3 answers

Mapstruct: HashMap as source to Object

How could I use a HashMap as source to an object? Here is my target object: public class ComponentStyleDTO{ private String attribute; private Object value; } I've tried to use this approach that I found and that is also in…
davis
  • 1,216
  • 5
  • 14
  • 27
9
votes
1 answer

Is there a auto mapping for spring pageable/sort with mapstruct

I like to use mapstruct, but i can't find out: is there a function to transform a Sort in Pageable for the mapped dto pageable to the entity pagable? Links: Pagable:…
Richard Stiller
  • 143
  • 1
  • 10
9
votes
2 answers

exclude specific fields in mapstruct

While I am trying to create a mapper between two classes in mapstruct, I am getting a warning when I compile my code : src/main/java/mapstruct/DogMapper.java:15: warning: Unmapped target property: "otherField". Cat convert(Dog dog); ^ 1…
Daniel Taub
  • 5,133
  • 7
  • 42
  • 72
9
votes
1 answer

Nested list mapping using MapStruct

How can I do the bean mapping using MapStruct for the below scenario. class Source { private String sourceId; private List courses; //always returns only one course } class Course { private String courseName; private List
Sai A
  • 191
  • 1
  • 3
  • 13
9
votes
4 answers

mapstruct and gradle configuratoin issue in Intellij IDEA

I have a project using gradle, and have mapstruct as one of dependency. everytime I tried to build project, it failed. I guess it is because Mapstruct will generate impl class that gradle was not able to find. Can anyone help me how to configure…
user3096841
  • 145
  • 2
  • 4
9
votes
3 answers

Mapping an object to an immutable object with builder (using immutables annotation processor) in mapstruct

We are using the immutables framework to generate all DTOs. Now we would like to map these objects one to another with mapstruct. But the generated DTOs are immutable and have no setters and no constructor, corresponding to the builder pattern. They…
Marc von Renteln
  • 1,229
  • 15
  • 34
9
votes
2 answers

How to manage Lazy Loading in Mapstruct?

I am dealing with a problem related with lazy loaded objects from the database. Let's say that we have the below entity. @Entity(name = "User") @Table(name = "USERS") public class User{ @Id @GeneratedValue private int id …
Dorin Brage
  • 158
  • 1
  • 5
  • 14
8
votes
3 answers

java: No implementation was created for ProductMapper due to having a problem in the erroneous element java.util.ArrayList

I'm trying to create very simple JUnit test into Spring Cloud project: @SpringBootTest(classes = {ProductMapper.class }) public class TestingWebApplicationTests { @Test public void contextLoads() { } } import…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
8
votes
4 answers

"Ambiguous constructors found" error when there more than one constructor when using MapStruct

I'm new to mapstruct. I'm trying to map ItemInfo to Item object and the following are my classes. public class ItemInfo { private String itemOwner; private String itemOwnerArea; //getters and setters } Following is the class that I'm…
Chamila Adhikarinayake
  • 3,588
  • 5
  • 25
  • 32
8
votes
1 answer

Mapstruct - ignore field by name in whole project

I've got project, where I often map dto -> db model. Almost all my db models have some additional fields, like version, which are never mapped from dto. Is there any possibility or elegant workaround to ignore target fields globally only by theirs…
rav137
  • 83
  • 1
  • 5
8
votes
1 answer

Why can't I reference a @Context parameter in the @Mapping attributes?

Using mapstruct, what I need is a mapping method with several sources and that these several sources are passed around to other mapping methods so I can have all my several sources for all mapping methods where I need these additional…
singe3
  • 2,065
  • 4
  • 30
  • 48
8
votes
1 answer

MapStruct : How to convert String to byte[] using mapstruct

In My dto class : private String password; In my model class: private byte[] password; I want to convert String to byte[] using mapStruct. Can someone help Thanks in advance.
Pratik Jaiswal
  • 390
  • 1
  • 5
  • 21
8
votes
1 answer

How to specify a default value for a boolean field using MapStruct

How can you specify a defaultValue when mapping a DTO using MapStruct? The following constructs did not work @Mapping(target = "used", defaultValue = "0") MyDTO toDto(MyEntity entity); @Mapping(target = "used", defaultValue = "false") MyDTO…
Omtara
  • 2,911
  • 2
  • 19
  • 31