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
182
votes
21 answers

MapStruct + Lombok together not compiling: unknown property in result type

Tech Stack being used : Java 8 MapStruct : 1.2.0.Final Lombok: 1.16.18 IDE: IntelliJ - Lombok Plugin already installed Initially, I faced issues when I removed getters and setters and added @Getter and @Setter annotation, mapstruct is not able to…
Vivek Gupta
  • 2,534
  • 3
  • 15
  • 28
94
votes
6 answers

IntelliJ Idea mapstruct java: Internal error in the mapping processor: java.lang.NullPointerException

After upgrading to the version 2020.3 of Idea i get a NullPointerException for the mapping processor. If anybody has a clue... Thank you!
Antonio
  • 1,008
  • 1
  • 7
  • 13
64
votes
8 answers

Mapstruct - How can I inject a spring dependency in the Generated Mapper class

I need to inject a spring service class in the generated mapper implementation, so that I can use it via @Mapping(target="x", expression="java(myservice.findById(id))")" Is this applicable in Mapstruct-1.0?
Karim Tawfik
  • 1,286
  • 1
  • 11
  • 21
64
votes
2 answers

Java mapping: Selma vs MapStruct

Currently there are two main popular Java Object to Object mapping frameworks that supersede Dozer (http://dozer.sourceforge.net/documentation/mappings.html), they are: Selma - http://www.selma-java.org/ MapStruct - http://mapstruct.org/ With the…
JackDev
  • 11,003
  • 12
  • 51
  • 68
49
votes
4 answers

Map custom method mapper to Mapstruct

I'm creating a poc for using Mapstruct in my future projects. Now I have one question how to map custom methods to a special target. For example I have following interface mapper: @Mapper public interface ItemMapper { static ItemMapper INSTANCE…
JimmyD
  • 2,629
  • 4
  • 29
  • 58
46
votes
9 answers

How to write Junit test for mapstruct abstract mapper injected via Spring

I'm using MapStruct, mapstruct-jdk8 version 1.1.0.Final and defining abstract class that I inject via Spring. I'm looking at how to be able to test them via Junit Test ? I've basicaly a main mapper that will use 2 sub mappers @Mapper(componentModel…
TheBakker
  • 2,852
  • 2
  • 28
  • 49
36
votes
2 answers

MapStruct ignore automatically unmapped properties

I am using MapStruct with big models (more than 50 fields) shared between different business use cases in my code. Depending on the entry point, some properties will be mapped and some not. When I build my project, I will always get the "WARNING:…
32
votes
3 answers

MapStruct Mapper as Spring Framework Converter - idiomatic use possible?

I'd like to combine MapStruct mappers with Spring's Conversion model. So I declare every Mapper interface as an extension of Spring's Converter: @Mapper public interface CarMapper extends Converter { @Override CarDto…
Ray
  • 3,084
  • 2
  • 19
  • 27
32
votes
4 answers

MapStruct QualifiedByName with multiple parameters

I have come across a situation where my mapping method has 3 parameters, and all the three are being used in deriving one of the properties of the target type. I have created a default mapping method in the interface keeping the logic for deriving…
Vivek Gupta
  • 2,534
  • 3
  • 15
  • 28
29
votes
16 answers

MapStruct - @Mapper annotation don't create bean

I downloaded application from this source https://github.com/springframeworkguru/spring5-mvc-rest/tree/vendor-api And I have a problem with MapStruct. @Mapper public interface CategoryMapper { CategoryMapper INSTANCE =…
Kutti
  • 486
  • 1
  • 6
  • 17
25
votes
6 answers

@AfterMapping is not called from @Mapper interface

I'm having trouble using Mapstruct. I am using a @Mapper annotated interface with @AfterMapping inside like follow: @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface ConfiguracionReautorizacionMapper { …
Jose A. Matarán
  • 1,044
  • 3
  • 13
  • 33
24
votes
1 answer

MapStruct: How to map to existing target?

I have a method in a service that updates an entity. It accepts object that has the data to update the entity. Dto object has less fields than entity but the fields have the same names. Could it be possible to use mapstruct for that routine job by…
Dennis Gloss
  • 2,307
  • 4
  • 21
  • 27
24
votes
2 answers

Map multiple fields to one with MapStruct

I have these 3 classes in separate files public class Book { @Id @GeneratedValue private Long id; @NonNull private String title; @NonNull private Author author; } public class Author { @Id @GeneratedValue …
Stelium
  • 1,207
  • 1
  • 12
  • 23
24
votes
2 answers

Mapstruct : Ambiguous mapping methods found for mapping collection element

I have two methods for mapping entity to domain. RDomain entityToDomain(REntity rEntity) /* this method ignores some of the fields in the domain. */ RDomain entityToDomainLight(REntity rEntity) I'm getting Ambiguous mapping methods found for…
santhosh
  • 405
  • 2
  • 6
  • 15
21
votes
10 answers

@MAPSTRUCT. No property named "packaging" exists in source parameter(s)

I am writing an MVC REST application with Spring Boot and Hibernate. I decided to do DTO mapping using MAPSTRUCT. It seems that I did everything according to the guide, but an error is issued. What is the problem, I cannot understand. There is very…
Artur Vartanyan
  • 589
  • 3
  • 10
  • 35
1
2 3
96 97