Questions tagged [mapstruct]

MapStruct is a code generator for creating efficient, type-safe bean-to-bean mappings in Java.

0
votes
0answers
27 views

Why do not I get the id when mapping from DTO to entity with mapstruct?

I have an API with spring boot and I use mapstruct and I just want to update the Person entity. For this, having PersonDto update Person. What I have so far: Mapper: @Mapper public interface ...
1
vote
0answers
68 views

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 ...
0
votes
1answer
38 views

Reusability of mappers

Is mapstruct the right tool for generating multiple models by reusing mapping code ? Example, I have a single input class: public class MySource { private String props; } and different target ...
0
votes
0answers
29 views

mapstruct - Update existing bean - ignoring 'id' field in all the child/nested beans (arraylists, sets etc..)

I have a parent class with many child entities. There are 2 instances of this parent class. Want to copy data of 1 instance to another one (ignoring the 'id' property in all the child entities) ---- ...
0
votes
0answers
37 views

AfterMapping issue on POST request - SPRING

I have an entity named User with multiple relationships with other entities. Well, I created a DTO for this entity and a Mapper using MapStruct. A get request is working fine, but when trying to make ...
0
votes
1answer
45 views

MapStruct / Java - Conversion Timestamp to Instant

I have this Mapper, and I want to convert a Entity to a DTO. My Entity contains the variable createdDate who is an Instant and my DTO contains commentedDate who is a Timestamp. I don't know how it's ...
1
vote
1answer
25 views

MapStruct not autowring with Spring-boot testing Gradle Junit5

I am trying to use mapstruct with Gradle, but I am having limited success. When I'm using it in the application everything seems to be working fine, but when I tried to write some tests Spring can't ...
0
votes
0answers
20 views

mapstruct not using spi configuration on a build server

Maptruct works locally in my IDE without any problems. But it seems the build server doesn't use the mapstruct spi configuration since it can't access custom getter and setter methods. The ...
0
votes
0answers
12 views

Mapstruct and @Cacheable

I have a class annotated with an org.mapstruct.Mapper and attempting to use an org.springframework.cache.annotation.Cacheable annotation on a method. That method is also annotated with org.mapstruct....
0
votes
1answer
31 views

Debug Mapstruct implementations with Eclipse

I'm using MapStruct 1.3.0.Final to convert Dtos into POJOs and vice versa with the spring value into mapstruct.defaultComponentModel option. Is there a way to debug generated implementations (by ...
0
votes
1answer
25 views

Reuse decorated mapper with Mapstruct

I'm using MapStruct 1.3.0.Final to convert Dtos into POJOs and vice versa with the spring value into mapstruct.defaultComponentModel option. To avoid stackoverflow errors due to bidirectional ...
1
vote
1answer
63 views

Mapstruct: Map a list inside an object to a list of objects

Given: public class Car { private String plate; private List<String> tires; } public class TirePlate { private String plate; private String tire; } I want to map all the Car.tires ...
0
votes
0answers
32 views

Showing a message whether the mapstruct annotation processor creates files or not - preferable for my custom 'generateMappers' task

Courtesy of M.Ricciuti who answered my initial 'Migrating from Gradle 4 to 5. How to get mapstruct 1.20.final working with it' question I've an addition question. Created a new new thread because 'add ...
1
vote
1answer
47 views

How to apply List in one field with MapStruct?

I have this POJO : public class PlayerDto { private Long id; private String name; private String past; } And I have this entity : public class Player { private Long id; ...
2
votes
1answer
72 views

Migrating from Gradle 4 to 5. How to get mapstruct 1.20.final working with it

We've use mapstruct 1.20.final for approx 1.5 years with various Gradle versions - latest gradle 4.10.2. We want to switch to Gradle 5.4.1, which works with everything except mapstruct. Our working ...
0
votes
1answer
24 views

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="...
0
votes
1answer
24 views

Mapstruct Invoking implicitly other mapper with multiple parameter

Given the following classes and a mapper that takes mulitple source arguments (I use lombok to keep source as short as possible.) @Getter @Setter public class MySourceOne { private String src1; } ...
1
vote
1answer
41 views

Is there a way to run programs using MapStruct without doing a maven clean install each time?

Mapstruct generates a class after doing mvn clean install, but if it's not done, and I run my spring boot application I get a class not found exception. I was wondering if there was anything I can do ...
0
votes
0answers
23 views

Eclipse cannot find generated source files in my junit tests

Hi I am facing an issue with eclipse. currently i have a java project using maven/springboot and i am using http://mapstruct.org/ libraries to generate some classes. In my test I am declaring the ...
2
votes
1answer
34 views

@Mapping with custom source and target variable is not working as expected when target has variable with same name as source

I have below Source and Target classes, i am using lombok for generating getters and setters public class Target { private String name; private String newName; } public class Source { ...
2
votes
1answer
35 views

Mapstruct how to construct a target object from 2 or more fields of the source object?

class PersonDTO { String name; String street; String city; } class Person { String name; Address address; } class Address { String street; String city; } @Mapper(componentModel = "...
1
vote
1answer
18 views

How to disable derived flag on generated source code from Mapstruct and how to generate Mapstruct classes only on local PC and not on build server?

First question: Mapstruct generates code to target annotation folder which has a marker "derived". This is ignored by RTC so I'm unable to check in the generated code (don't ask me why I want to do ...
0
votes
0answers
52 views

Mapstruct expression mappings using multiple source parameters

I am trying to map two fields to a single object, where the relevant fields are list objects and the said object cannot be changed. @Mapping(target = "myWrapperObject.myListObject", ...
0
votes
1answer
52 views

Approach for Mapstruct Mappers with method overloading and InheritedConfiguration

We are using MapStruct with Spring Data to convert between JPA entities and DTO classes. All the mappers follow the same pattern with methods beanToDTO() and dtoToBean(). After a learning cure, we ...
1
vote
1answer
45 views

Most suitable way to transport entities from service to front end in Spring boot

I have currently found out three possible ways to send objects (entities) from service to the front end. JSON views DTO using MapStruct for example. DTO without MapStruct (as per first comment) I ...
0
votes
1answer
29 views

Is there an annotation to ignore mapping a specific abstract method that will be overridden in a child class?

I'm looking to use mapstruct on many methods in a hierarchy of classes, but I need some of the abstract methods at higher levels not be automatically mapped by mapstruct, as they will have full ...
2
votes
1answer
93 views

MapStruct does not detect setters in builder

I am building a simple REST service using spring. I separated my entities from DTOs and I made the DTOs immutable using Immutables. I needed mapping between DTOs and DAOs, so I chose MapStruct. The ...
2
votes
0answers
51 views

Object with field name “setCode” throws => Unknown property “setCode” in result type

We are using mapstruct to map objects. And in one of the case we have defined the mapping using @Mapping annotation like below: @Mapping(source = "glSetCode", target = "setCode") and we are ...
1
vote
2answers
94 views

Unmapped target property warning when property name starts with “set”

I'm trying to implement a mapping between an entity and DTO using MapStruct. One of the properties to be mapped is "settlementDate". It has the same name in DTO class and the mapping works, but I get ...
0
votes
1answer
27 views

Copy list with conditional mapping

I have a list of 1.Address object with ID,Street name,City and PostalCode and a list of 2.Contact object with ID, Street,City and Phone. Can i copy Street name and City alone from List of Contact ...
0
votes
1answer
59 views

Mapstruct constructor injection (spring)

In mapstruct 1.3.0.Final we have dependency injection via constructor. Documentation says: The generated mapper will inject all classes defined in the uses attribute (...) For ...
0
votes
1answer
48 views

Need to merge two source objects into target object using mapstruct ,here one field in source1 has List and in source2 that is string

public class Source1 { private String name; //srihari private List<String> city_names; //city_names.add("hyderabad-india") } public class Soruce2 { private String ...
0
votes
0answers
34 views

Mapstruct Kotlin multimodule app NonExistentClass

Hi I use mapstruct to conver models to Dto classes thats in another module. When mvn clean install it says cannot find symbol in impl it wrotes NonExistentClass instead of my dto classes. If I write ...
1
vote
2answers
51 views

Mapstruct: Mapping of “dirty” string fields to double

Given: String SourcePojo.area = "120,5 sqm" double TargetPojo.area = 120.5 I can convert the "dirty" string into the number by: double extractDoubleFromString(String string) throws ParseException{ ...
0
votes
1answer
40 views

Mapstruct: How to use custom mappers with @MappingTarget

I am using Mapstruct and I need to update an existing bean using @MappingTarget, but need to apply some complex logic to set the correct field in the target. Lets say I have a target bean that looks ...
1
vote
2answers
48 views

Mapping objects with bi-directional relations with Mapstruct

I wonder if and how Mapstruct could help with mapping ojects with bi-directional relations (in my case one to many): public class A{ private Set<B> listB; } public class B{ private ...
1
vote
1answer
91 views

Can't generate mapping method with no input arguments with Mapstruct

I’m starting my very first steps with Mapstruct mapper. I want to map a JPA data entity class to a DTO class. This is my source class: @Entity @Data @Table(name = "projects") public class Project { ...
2
votes
2answers
170 views

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 ...
0
votes
0answers
40 views

MapStruct - weld injection for second mapper not working

I have a problem with injection in weld cdi for mappers using mapstruct library. When I have only one mapper everything is working. After adding second mapper this mapper throws exception: Caused by: ...
0
votes
1answer
49 views

Mapstruct: map list properties by use of a qualified IterableMapping

At first, let me apologize if this question was already posed. I could not find any reference in StackOverflow. I am trying to use a qualification in my mapping between beans via MapStruct, so as to ...
0
votes
1answer
88 views

Spring Mapping using a custom mapper method

I have two objects with all the same members except for the date member. In Obj1.date is a java.sql.Date, and Obj2.date is a long (epoch). I need to write a mapper to map obj1 to obj2. This is what I ...
0
votes
1answer
47 views

Mapstruct -empty set

I use Mapstruct in my project. In one of the entities I have the set [oneToMany] structure. When I retrieve all data using findAll () in the repository, if there are no bindings, then an empty HashSet ...
0
votes
1answer
244 views

Mapstruct with @MappingTarget don't call lombok Builder build()

I'm trying to create patch method with Mapstruct mapping and Lombok Builder. But in generated code missing build() call Mapper with removing null values: @Mapper( nullValueCheckStrategy = ...
0
votes
2answers
75 views

Q: Can mapstruct understand that an expression returns a String so that it can use my dateFormat I provide?

I'm trying to get Mapstruct to understand a source expression is a string that it can format into a java.util.LocalDate, but I'm not sure I'm doing it right. I tried following the directions in the ...
0
votes
1answer
210 views

Easiest Way for MapStruct to map a default for all properties of an object

Suppose I have a target object MyObject { boolean myBoolean; int myInt; ... } where fields myBoolean and myInt are required (i.e., if you try to call build() on the Builder for MyObject ...
1
vote
1answer
151 views

Mapping element of a list of different type with mapstruct

We are mapping a object that have a list of object that all implement a parent interface but may have a different implementation. But it seem when we are mapping the list only the value from ...
0
votes
1answer
106 views

MapStruct: filter a list before mapping

I've seen this question asked elsewhere but not quite in the same context and without an answer that works for our use case. Suppose I have a list field in a source object: List<MySourceElement&...
-2
votes
1answer
97 views

String value to enum mapping when string neither matches enum value nor name

I'm trying to map from a String value to an enum that does not match that string value directly (i.e. String value is "I" and I want to map that to enum value Industry.CREATOR) I'm not seeing anything ...
0
votes
1answer
61 views

MapStruct: Difference between BeanMapping and Mapping

I have been going through the documentation of MapStruct and can't seem to figure out when the annotation @BeanMapping should be used. The documentation seems to extensively use just @Mapping for most ...
0
votes
1answer
100 views

Setting nullValueMappingStrategy on the mapper / mapper config level for categories of mappings

MapStruct documentation has the following to say about the sensible defaults chosen for NullValueMappingStrategy.RETURN_DEFAULT: Bean mappings: an 'empty' target bean will be returned, with the ...