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
15
votes
4 answers

Map struct : When source is null, target should NOT be set to null

I am trying to map nested properties using mapstruct 1.2.0.CR2. (Example map customer.address.houseNumber to userDTO.homeDTO.addressDTO.houseNo ). Expectation : I do not want to set the addressDTO to null when customer.address is null. Since…
Malathi Damodaran
  • 229
  • 1
  • 3
  • 8
15
votes
10 answers

MapStruct implementation is not working in Spring Boot Web Application

I am a newbie to Spring Boot and MapStruct Tool. Earlier, A Project(written by other team using these technologies) is not starting up. Then, I had made some changes in Mapper Abstract Class but now mapper object is coming as null on application…
Ankit
  • 2,126
  • 4
  • 33
  • 53
15
votes
1 answer

MapStruct : enrich mapping annotation to define custom mapper

Here is my context: I am using byteBuddy to dynamically generate a class that transform an object into another one based on a external configuration. I encountered some issues and I wanted to find an alternative that's how I discovered MapStruct. So…
nbchn
  • 328
  • 1
  • 4
  • 16
14
votes
1 answer

MapStruct - How to set different null strategy for different mapping methods?

I want to have a single Mapper class with both create and update methods. The generated code for create method is fine, but in case of update, I want to set the properties in the target, only if they are not null in the source. How do I do it with…
gaganbm
  • 2,663
  • 3
  • 24
  • 36
14
votes
2 answers

Mapping nested object with mapstruct

i create mapping like below. How to map flat dto object properties like (street, city, etc) to nested address in domain object. When I try to I've got an error: [ERROR] diagnostic: Unknown property "address.postalCode" in return type. …
Piotr Sobolewski
  • 2,024
  • 4
  • 28
  • 42
13
votes
2 answers

Turn off "builders" in MapStruct when using Immutables

How do I completely disable using "builders" in MapStruct? I don't want to use them at all as they are causing all kinds of issues for me. I created the service file under META-INF (I would prefer a way to assign it to the mapping builder= but I…
KJQ
  • 447
  • 1
  • 7
  • 28
13
votes
7 answers

MapStruct is not generating implementation classes

I am using Mapstruct and Lombok with maven and IDEA and it is refusing to generate mappers implementation. Config:
user3495816
  • 567
  • 1
  • 6
  • 17
13
votes
2 answers

mapstruct map an id to an object

i have an object school that has an object person, persons are already saved in a data base and when i save a school object i give it a person id so in the class school i have an attribute person of type Person, and in SchoolDTO i have an attribute…
Aymen Kanzari
  • 1,765
  • 7
  • 41
  • 73
13
votes
2 answers

Is there a global setting in Mapstruct that will trim a string value prior to setting it to a destination bean property

Is it possible to trim a string value before it is set against a bean property of type string in the destination bean? Dozer offers such a facility through its mapping configuration for example,
13
votes
2 answers

MapStruct String to List mapping

How would i map String to List and List to String? Consider we have following classess class People{ private String primaryEmailAddress; private String secondaryEmailAddress; private List phones; //getter and…
suresh
  • 341
  • 2
  • 3
  • 13
13
votes
8 answers

Mapstruct generated class not being injected by Spring in JHipster web app

I'm developing a web app created with JHipster v2.20.0. Using Eclipse 4.5.0 WTP as IDE. The Spring configuration is annotation based. I've just merged this pull with our code. When I try to run the application inside Eclipse I get this…
Rafael Leite
  • 147
  • 1
  • 1
  • 13
12
votes
4 answers

java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because "resource" is null at org.mapstruct

mvn compilation using Idea works fine. Fails during App.main start. Works well on older Idea on other PC on Ubuntu. ENV: Intellij 2020.3.2 as admin; Java 15.02; Windows 10 x64; latest mapstruct. How to fix…
Arthur
  • 575
  • 3
  • 8
  • 16
12
votes
3 answers

How to instruct Mapstruct to use lombok builder?

MapStruct is unable to create an implementation when I'm trying to map object with a private default constructor, but with a (lombok generated) builder. SomeMapperImpl.java:[20,27] SomeDto() is not public in com.example.mapstructdemo.dto.SomeDto;…
Robert van der Spek
  • 1,017
  • 3
  • 16
  • 37
12
votes
1 answer

Mapstruct bidirectional mapping

I have the following example in which i have a separate domain layer and a separate persistence layer. I am using Mapstruct for mapping and I get StackOverflow when mapping from domain to entity or from entity to domain because of the bidirectional…
2dor
  • 851
  • 3
  • 15
  • 35
12
votes
4 answers

Mapstruct : Use of context in source argument of @Mapping

When using multiple arguments in a @Mapper, it seems that the @Context arguments is unreachable public interface MyMapper { @Mapping(target="target1", source="arg1.arg") //works @Mapping(target="target2", source="arg2") //works …
Filip
  • 906
  • 3
  • 11
  • 33
1 2
3
96 97