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
10
votes
2 answers

How can I use another mapping from different class in mapstruct

I would like to mapping a model object to dto model. I already have mapper for one of the object. How can I reuse this mapper in another mapper which is in another class? I have below as model @Getter @AllArgsConstructor @ToString …
user293655
  • 508
  • 1
  • 6
  • 23
10
votes
1 answer

Is it good to upgrade to MapStruct from ModelMapper?

Currently we are using ModelMapper in our project. However in the site i see there are lot of likes for MapStruct. Not sure the differences and whether we need to really go for an upgrade. What are the differences between ModelMapper and MapStruct…
Java Architect
  • 201
  • 3
  • 5
10
votes
3 answers

How to inject(custructor) a spring bean into abstract mapper of Mapstruct?

I am having below mapper class in which I want to use CounterService. I am trying constructor injection but that's not working and null is printing. @Mapper(componentModel = "spring", uses = CounterService.class, injectionStrategy =…
The Coder
  • 3,447
  • 7
  • 46
  • 81
10
votes
2 answers

How to use MapStruct for different data types?

I have two types of data that I want to map: SignUpUserDto: public class SignUpUserDto { private String firstName; private String lastName; private String username; private String email; private String password; private…
Robert
  • 186
  • 3
  • 6
  • 16
10
votes
1 answer

mapstruct - Propagate parent field value to collection of nested objects

Is it possible to propagate value form a parent object to collection of nested objects? For example Source DTO classes class CarDTO { private String name; private long userId; private Set wheels; }; class WheelDto { private…
antohoho
  • 950
  • 2
  • 17
  • 37
10
votes
1 answer

Passing additional parameters to MapStruct mapper

Haven't figured out how to pass in additional arguments or an alternative. Currently I'm mapping an Order and OrderLines. Both objects are different and need @mappings. Example I have an Order and OrderRequest object both are different and need…
shadley
  • 145
  • 2
  • 2
  • 6
10
votes
2 answers

MapStruct: map nested object properties to properties

Assume I have the following objects: class Person { String firstName; String lastName; } class PersonBLO { Person person; Integer foo; // Some calculated business property } class PersonDTO { String firstName; String…
JIN
  • 647
  • 1
  • 7
  • 19
10
votes
1 answer

mapstruct: update existing field of entity using data from DTO

I recently added mapStruct in my project. This framework is cool, but I can not figure out one thing. This is my case: I have Profile entity and field with the Person type. I want to update it using ProfileDto. I am using void fromDto(ProfileDto…
yaroslavTir
  • 711
  • 2
  • 10
  • 22
10
votes
2 answers

Map a dto to an entity retrieved from database if Dto has Id using MapStruct

I'm using MapStruct to make dto <-> entity mapping. The same mappers are used to create and update entities from dtos. A verification of the dto's id is done to know whether a new entity must be created (id == null) or it should be retrieved from…
Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80
9
votes
2 answers

No method found annotated with @Named#value

I'm having trouble using MapStruct version 1.4.1 when I'm trying to implement my own mapping. This is code that I wrote: package com.kucazdravlja.user.mappers; import com.kucazdravlja.user.dto.NoticeBoardDto; import…
laban_luka
  • 399
  • 1
  • 4
  • 11
9
votes
2 answers

How to map parent and children using Mapstruct in Spring Boot?

I have parent (product) and children(book,furniture), and would like to map product entity to product DTO. As you can see, the product is mapped and stored in single table in database. How can I map the parent, product, that has extra details of its…
Daniel
  • 478
  • 3
  • 16
  • 32
9
votes
3 answers

How to fill in map inside target object by copying values from source object using -MapStruct?

I am new to Mapstruct. I have a scenario where, in my target object I have a java map with key value pair and I have to fill this map using source objects inner object properties/data member values. My code is something like…
Anonymous
  • 1,726
  • 4
  • 22
  • 47
9
votes
2 answers

IntelliJ Idea: Maven compilation warning about supported annotation processor source version 'RELEASE_6' on Java 11

Upon mvn clean install smart execution in IntelliJ Idea using Java 11 I get the following warning: Warning:java: Supported source version 'RELEASE_6' from annotation processor 'net.java.dev.hickory.prism.internal.PrismGenerator' less than -source…
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
9
votes
2 answers

How to Convert String to Date using MapStruct in Java?

I am using MapStruct to map values from a source to a target class. The source class has a String property and the target class has a java.util.Date property. The source property is like this: "yyyy-mm-dd". And I want to convert this String property…
elvis
  • 956
  • 9
  • 33
  • 56
9
votes
3 answers

Is Mapstruct Java11 compatible?

I'm a bit confused. There is some documentation that says java 9 is "experimental": https://mapstruct.org/documentation/stable/reference/html/#_using_mapstruct_on_java_9 And I found a post where a guy was having trouble in Java 10. So we are…
markthegrea
  • 3,731
  • 7
  • 55
  • 78