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

How can only specified fields be mapped using MapStruct?

MapStruct is mapping all the properties of source and destination by default if they have same name. The ignore element in @Mapping can be used for omitting any field mapping. But that's not I want. I want control over the mapping strategy. I want…
Naveen
  • 403
  • 1
  • 6
  • 20
12
votes
2 answers

MapStruct: mapping from java.util.Map to Bean?

I currently have a Map that contains values in the form key = value and I would like to "expand" those into a real object. Is it possible to automate that with MapStruct and how would I do that? To clarify: The code I would write by…
TwoThe
  • 13,879
  • 6
  • 30
  • 54
12
votes
2 answers

Can't map property when using MapStruct

I am using MapStruct library to map objects but I got this error: Can't map property "java.util.Date aDate" to "javax.xml.bind.JAXBElement ADATE". Consider to declare/implement a mapping method: "javax.xml.bind.JAXBElement map(java.util.Date…
zygimantus
  • 3,649
  • 4
  • 39
  • 54
11
votes
2 answers

DDD: Where to raise "created" domain event

I struggle to find and implement the best practise for the following problem: where is the best location to raise create domain event (the event that notifies for the creation of an aggregate). For example if we have Order aggregate in our bounded…
kirpt
  • 795
  • 11
  • 21
11
votes
4 answers

Mapstruct problem: Unknown property error, but property is present

I'm using: spring-boot 2.1.5.RELEASE mapstruct 1.3.0.Final lombok 1.18.8 and I'm trying to map two objects, Model and DTO: DTO ClientDto - gotten from nesux repository as a dependency Model Client in both classes has a property settlementCentre,…
Dmitry Chkoniya
  • 111
  • 1
  • 1
  • 4
11
votes
2 answers

How to properly integrate MapStruct with Eclipse? (Including Lombok java agent)

I'm willing to use MapStruct in some official project so I decided to give it some testing first; I'd need to make it work integrated with eclipse and followed all the instructions provided on MapStruct website but ... so far no luck. Did anyone…
Andrea Saba
  • 331
  • 1
  • 3
  • 6
11
votes
3 answers

mapstruct map iterable to non iterable

I want to map a list of Objects to an Object that contains a list: public class Group { private List people; } public class Person { private String name; } I tried creating a mapper like this: Group toGroup(List
John Ellis
  • 173
  • 2
  • 2
  • 7
11
votes
2 answers

Set null to target using mapstruct

I am using mapstruct and I am wondering if there are any ways to set null value for some target properties. For example, public class MySource { private String prop1; private String prop2; public MySource() { // Initialization. …
Georgios Syngouroglou
  • 18,813
  • 9
  • 90
  • 92
11
votes
2 answers

How to map extended DTO's from same source class

I've started using Mapstruct to map JPA entities to DTO's. For basic entities, this works great. My problem: Some entities have lazy loaded collections, containing additional details, that I don't want always want to fetch and map. As a solution…
Steen
  • 311
  • 1
  • 3
  • 11
11
votes
4 answers

Unknown Property in a return type

I am trying to use mapstruct in my Play 2.4 Java8 JPA project. Steps I have done: Added Dependency "org.mapstruct" % "mapstruct-jdk8" % "1.1.0.Beta1", "org.mapstruct" % "mapstruct-processor" % "1.1.0.Beta1" Model @Entity public class Employee…
singhakash
  • 7,891
  • 6
  • 31
  • 65
11
votes
5 answers

Prevent Cyclic references when converting with MapStruct

Today I started using MapStruct to create my Model to DTO converters for my project and i was wondering if it handled cyclic references automatically but it turned out it doesn't. This is the converter i made to test it: package…
valepu
  • 3,136
  • 7
  • 36
  • 67
11
votes
2 answers

MapStruct: Mapping 2 objects to a 3rd one

I have Object1 and Object2. Now, I want to map object3, with attributes from 1 & 2. Say, I have 2 object: 1. User: {first_name, last_name, id} 2. Address: {street, locality, city, state, pin, id} Now, with these, I want to map that in User_View:…
anij
  • 1,322
  • 5
  • 23
  • 39
10
votes
2 answers

How to tell MapStruct "not" to use the Lombok Builder?

I have the following classes and mapper to map them. How can I configure Mapstruct to "not" use the Lombok builder? (without removing the @Builder annotation)? When using the latest version of Lombok and mapstruct, mapstruct will automatically use…
edbras
  • 4,145
  • 9
  • 41
  • 78
10
votes
6 answers

MapStruct mapper returns empty mapped object

I'm trying to use MapStruct to map convert between dto and entity objects, however the generated mapper implementation only returns empty mapped object. BeerMapperImpl @Generated( value = "org.mapstruct.ap.MappingProcessor", date =…
jiangwensi
  • 113
  • 2
  • 5
10
votes
3 answers

Is there a way to map an empty String to null using MapStruct?

I am using MapStruct for mapping a DTO to an entity and vice versa in my Spring Boot application. Is there a way to map empty strings to null using @Mapping?
Saurabh Gupta
  • 315
  • 1
  • 5
  • 14