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
20
votes
1 answer

Mapstruct: Ignore specific field only for collection mapping

I am using following mapper to map entities: public interface AssigmentFileMapper { AssigmentFileDTO assigmentFileToAssigmentFileDTO(AssigmentFile assigmentFile); AssigmentFile assigmentFileDTOToAssigmentFile(AssigmentFileDTO…
Dmitry K
  • 1,142
  • 2
  • 16
  • 27
20
votes
10 answers

MapStruct requires Impl class

I have next classes: Mapper public interface DeviceTokensMapper { DeviceTokensMapper INSTANCE = Mappers.getMapper(DeviceTokensMapper.class); @Mappings({ @Mapping(source = "tokenName", target = "tokenName"), …
Iurii
  • 1,755
  • 8
  • 24
  • 38
18
votes
2 answers

Difference between jackson objectMapper to others

I can't find any explanation about difference between jackson's ObjectMapper to other mappers like dozer/mapStruct/modelMapping/etc. All the articles compare dozer/mapStruct/modelMapping but they ignore ObjectMapper. I can't understand what is…
Plaggyy
  • 219
  • 1
  • 2
  • 8
18
votes
6 answers

MapStruct : mocking nested mapper

I using MapStruct to map my entities, and I'm mocking my objects using Mockito. I want to test a method that contains a mapping with mapStruct. The problem is the nested mapper is always null in my unit tests (works well in the application) this is…
ihebiheb
  • 3,673
  • 3
  • 46
  • 55
18
votes
2 answers

Mapping List from List using mapstruct
Hi I am getting null for List action in DTO while setting it from the Child Source class using mapstruct. Could some help me in resolving this. Please find my code here Entity Class: public class Source { int id; String name; …
bhuvana
  • 181
  • 1
  • 1
  • 3
18
votes
3 answers

Map a collection with parameter with mapstruct

To map a certain object with mapstruct I need some custom post processing which needs an additional parameter to do it's work: @Mapper public abstract class AlertConfigActionMapper { @Mappings({ @Mapping(target = "label", ignore = true)}) …
Stijn Geukens
  • 15,454
  • 8
  • 66
  • 101
17
votes
1 answer

How to map nested collections using MapStruct?

I have 2 entities: Entity 1: public class Master { private int id; private Set subMasters= new HashSet(0); } public class SubMaster{ private int subId; private String subName; } Entity 2: public class…
gschambial
  • 1,383
  • 2
  • 11
  • 22
16
votes
12 answers

MapStruct - Cannot find implementation

Using latest Springboot and MapStruct versions and building with Maven, I am trying to implement the "Start Here" example given in the official MapStruct site My code is even…
ElPiter
  • 4,046
  • 9
  • 51
  • 80
16
votes
2 answers

Proper way of using and testing generated mapper

Recently we encountered some conflict during the development of our system. We discovered, that we have 3 different approaches to testing in our team, and we need to decide which one is best and check if there is nothing better than this. First,…
ŁukaszG
  • 596
  • 1
  • 3
  • 16
16
votes
2 answers

How can I map properties conditionally with MapStruct 1.2?

Is it possible with MapStruct 1.2 to map a source property with a specific value to a specific different value in the target? I think about something like this: public abstract class JiraKpmMapper { @Mappings({ @Mapping(source =…
du-it
  • 2,561
  • 8
  • 42
  • 80
16
votes
2 answers

Java: Unmapped target properties

I have a problem with Mapper.I am using a mapstruct-processor to build Maven project. All time I get a warning: Warning:(15, 16) java: Unmapped target properties: "from, to". Warning:(13, 13) java: Unmapped target properties: "clientFrom,…
Błażej Rejnowski
  • 239
  • 1
  • 2
  • 8
16
votes
2 answers

Nested Mapping in Mapstruct

I am new to MapStruct API, can anyone say how to do nested Mapping? I have two classes one is my actual PurchaseOrder class, which is known as my target class, and the other is EDPurchaseOrder class which is known as the source file, Don't worry…
AdamIJK
  • 615
  • 2
  • 12
  • 22
16
votes
1 answer

Map multiple source fields to same type target fields with Mapstruct

Consider the following POJOs: public class SchedulePayload { public String name; public String scheduler; public PeriodPayload notificationPeriod; public PeriodPayload schedulePeriod; } private class Lecture { public…
giannoug
  • 643
  • 3
  • 8
  • 20
15
votes
5 answers

Mapstruct - Ambiguous mapping methods found for mapping property

I am using mapstruct to map from one DTO to another. I have multiple default methods , but 2 of them with a return value of String and that uses the same class as the input parameter gives me "Ambiguous mapping methods using java Mapstruct" error. I…
ljs
  • 495
  • 1
  • 8
  • 23
15
votes
3 answers

From string to enum using mapstruct

I want to convert String to enum using mapstruct enum TestEnum { NO("no"); String code; TestEnum(String code) { this.code = code } public String getCode() { return code; } } I have a code that I've got from service and…
m.zemlyanoi
  • 335
  • 1
  • 5
  • 15
1
2
3
96 97