Questions tagged [mapstruct]
MapStruct is a code generator for creating efficient, type-safe bean-to-bean mappings in Java.
1,468
questions
0
votes
1
answer
23
views
Mapping a field to specific source value when there are multiple sources
Hey guys I'm having an issue right now. I have a mapper to map a request to response also a CC5Response to response. I'm doing it in one method. But the problem is the field order id is both in ...
0
votes
1
answer
45
views
Not able to map SuperClass with a nested Object, while mapping child class
I am trying to map classes using MapStruct. I have Super class and child class extending it. The fields are mapped correctly in BaseMapper generated code, but in the ChildMapperImpl, the fields from ...
0
votes
1
answer
53
views
Mapstruct Internal error in mapping processor: Java.lang.NullPointerExecption at org.mapstruct.ap.internal.model.Type.hasAccessibleConstructor
lombok: 1.18.30
org.mapstruct.version: 1.4.2.Final
JDK 11
Intellij 2023.2.5 Community Eddition
I am trying to use Mapstruct to map Some objects. Whenever I try to compile using mvn -clean install. It ...
1
vote
1
answer
36
views
How To Convert a Bi-Directional Link With MapStrcut
Here below is a very simplified car sharing model, where a Car might be used by more than one User. I need to convert a service object into a DTO object and vice-versa:
@Data
public class Car {
...
-1
votes
0
answers
47
views
Map Java Class to Proto Class Using Mapstruct
While performing mapping from a Java class to an automatically generated protobuf class using MapStruct in Java, I encounter an error. The details of the error are as follows:
If I were to give an ...
0
votes
0
answers
19
views
How to InheritConfiguration from prototype of mapping method of iterable types using Mapstruct?
I have created a MapperConfig where I have a prototype of mapping method that can be used to inherit method-level mapping annotations.
@MapperConfig(componentModel = MappingConstants.ComponentModel....
0
votes
0
answers
62
views
Map enum values to class constants
In our code base, we have a lot of pseudo-enums:
public final class Target extends PseudoEnum {
public static final ErrorCode FOO = new ErrorCode(1);
public static final ErrorCode BAR = new ...
0
votes
1
answer
67
views
Best way to handle identical data within two different Java types generated from XSD files
I am pretty much stuck finding the best way to solve this.
My case is that I have a provider which gives me XSD files to generate the types I will use to call their SOAP api. Those XSD files sometimes ...
0
votes
0
answers
20
views
Mapstruct - ignore field for the whole mapper
Is there any possibility to ignore some field, eg @Mapping(ignore = true, target = "dontWantToLazyFetchFromDbSometimes")? I have mapper where sometimes the common object has list of objects ...
0
votes
0
answers
25
views
(Java, MapStruct) Is it possible to map fields from a nested object to an extended target object that shares a common base class?
So, I have a lilttle bit of a conundrum. I know these class names might be a little confusing, apologies.
Let’s say these are the objects I’m working with:
@Getter
@Setter
public class EntityPO {
...
0
votes
1
answer
49
views
Merge objects/maps with mapstruct
I have two objects of the same type. All fields are Map<String, SomeType>, so the objects look like:
class Obj {
Map<String, TypeA> propA;
Map<String, TypeB> propB;
...
Obj ...
0
votes
0
answers
50
views
MapStruct dependency form a cycle
Working with new project I run into issue of cycling dependency, that did not occurred in previous projects. The only difference is me using constructor injection rather than field injection like in ...
0
votes
0
answers
19
views
Mapstruct explicitly map to subclass
I have these Dtos:
public class AnimalDTO {
Long id;
String name;
}
public class DogDTO extends AnimalDTO {
Long furType;
String furColor;
...
}
public class ...
0
votes
1
answer
24
views
Spring data jpa - How to make a selection on children and output the parents with all selected children?
I have thoses entities
@Entity
@Data
@Table(name = "CITY")
public class CityEntity {
@Id private int id;
private String name;
private String postcode;
@OneToMany(fetch = ...
1
vote
1
answer
108
views
Mapstruct Mapper Error : Cannot Find Symbol
I had existing mapper in code. I am trying to modify it.
Line Before Mapping is as follow. I was directly mapping id to id.
@Mapping(target = "id", source = "source.id")
public ...
0
votes
1
answer
47
views
Mapstruck null failure for inner field mapped by another mapper
In my application, each chat contains a list of messages, and each message contains info about the users who are their sender and receiver. However, I’m struggling to use a mapper with mapstruct that ...
0
votes
1
answer
27
views
Mapstruct not generating implementations with Maven and Kotlin
as you've read in the title, I have a problem using Mapstruct with Kotlin and Maven.
(FYI: The solutions in this post didn't resolve the issue for me).
Following mapstruct-examples/mapstruct-kotlin, I'...
-1
votes
1
answer
55
views
Springboot JPA HQL Query
Im tinkering to learn more about springboot jpa and mapstruct
I got 2 entity class and using pgadmin4 for postgresql.
PostQuestions have a foreign key userId to Users table
I currently want to do a @...
0
votes
1
answer
107
views
Parameter x of constructor in ... required a bean of type '...' that could not be found [closed]
I am working on a personal project with Spring Boot. I am getting the following error:
Parameter 2 of constructor in com.learningapp.backend.AcademixHub.services.UserService required a bean of type '...
0
votes
0
answers
55
views
MapStruct with MappingTarget in SpringBoot
I am using MapStruct in my SpringBoot project. The below mapper maps all the fields from the entity to the DTO object of User and Accounts. However ehen trying to do a @MappingTarget after the DTO is ...
2
votes
1
answer
90
views
A Mapstruct mapper isn't injected
There's something weird going on. My Mapstruct mapper is not being registered as a Spring component even though the IntelliJ UI says it is. It causes my controller test to fail
@RestController
@...
0
votes
1
answer
87
views
The option mapstruct.defaultComponentModel is not being recognized
I have this configuration in my pom.xml file:
<properties>
<java.version>11</java.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
&...
0
votes
0
answers
67
views
Can my decorated mapper be a @Component and be tested as a unit as well?
If I want to test my decorated mapper as a unit, I need this setup:
@Mapper(componentModel = "default")
@DecoratedWith(CardMapperDecorator.class)
public interface CardMapper {
public ...
0
votes
1
answer
52
views
MapStruct - working in one place but not the other
I've been having problems with mapstruct the last few days. It was supposed to be a simple job until something weird started happening.
I have BusinessUnit (BU) , UserBusinessUnitRole (UBUR) and Role.
...
1
vote
2
answers
84
views
How do I get an instance of my decorated Mapstruct mapper in a unit test?
I want to test a Mapstruct mapper. The code below works if I make my test integrational and annotate it with @SpringBootTest. However, I want to make it a unit test instead. How do I get that ...
0
votes
0
answers
64
views
Mapstruct's generated mapper doesn't call the super constructor. How do I fix it?
I have this mapper:
@Mapper(componentModel = "spring")
@DecoratedWith(CardMapperDecorator.class)
public interface CardMapper {
And this mapper decorator:
@Component
@RequiredArgsConstructor
...
0
votes
2
answers
44
views
Mapstruct set whole property to null instead of all properties in nested class
My current mapper looks like this:
public abstract OwnerResponse toOwnerResponse(Owner owner);
A Owner has basic properties like, id, name etc. Mapping these works properly.
Now Owner also has a ...
1
vote
3
answers
89
views
How Spring Mapstruct gets info of Lazy initialized entity field?
I have two entities with ManyToOne relationship and lazy fetch type:
@Entity
public class Item {
private Long id;
private String title;
@ManyToOne(fetch = FetchType.LAZY)
private Category ...
0
votes
0
answers
115
views
Properties from the super class are not mapped. MapStruct to map field in base class
Unknown property "parentField" in target. I can't set parentField to Child class, however there are setters and getters
public class Parent {
String parentField;
}
public class Child ...
0
votes
1
answer
132
views
How to set Mapping in Mapstruct to get the Parent's field in Child's DTO?
public class Parent {
String parentField;
}
public class Child extends Parent{
}
public class ChildDTO{
String parentField;
}
@Mapper (componentModel="spring")
public interface ...
2
votes
1
answer
304
views
MapStruct record to record mapping does not work
I try to convert a Java record from one package to another.
@Mapper
public interface KriteriumMapper {
KriteriumMapper INSTANCE = Mappers.getMapper(KriteriumMapper.class);
de.model.Kriterium ...
0
votes
1
answer
46
views
How to reference mappers injected into a mapstruct mapper by the annotation "uses"
I have defined a mapstruct interface, which makes use of two other mapstruct mappers:
@Mapper(componentModel = "spring", uses = {Mapper1.class, Mapper2.class})
public interface ParentMapper{
...
0
votes
0
answers
37
views
@MockBean on a MapStruct interface in a Spring @WebMvcTest does not work
Given the following controller in a Spring Boot 3 application:
// REST controller class
@RestController
@RequestMapping("/bookings")
@RequiredArgsConstructor
class BookingController {
...
0
votes
0
answers
41
views
Back referencing object with mapstruct
I have these entities
@Entity
@Table(name = "author")
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor(access = PROTECTED)
@Setter
@Getter
@SuperBuilder
@JsonInclude(JsonInclude....
0
votes
0
answers
139
views
Spring Boot update field value to Null?
I have an object that has a field with existing value, for example:
{
"id": 1,
"classID": 2
}
Now I want to set the field classID from 2 to NULL through PUT method.
This is my ...
1
vote
2
answers
201
views
Mapstruct ignore field, warning unmapped target properties
I am using mapstruct in Java and I need to get rid of warning: Warning: Unmapped target properties: "t3". I have the following structure:
class A {
String t1;
String t2;
}
class B {
...
0
votes
1
answer
441
views
why compile error when upgrade lombok to 1.18.28 with jdk17?
I'm upgrading the Java version to 17. Here is the stacktrace.
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private com.sun.tools.javac.processing....
0
votes
1
answer
332
views
How can I create a decorator with Mapstruct in my Spring boot application?
I have a Spring boot application where auto component scan is enabled and mapstruct seems to be set up correctly, since it works on basic mappings created on interfaces, but I can't seem to add a ...
4
votes
1
answer
39
views
Single Item from Entity Collection into Nested Dto
I have a entity Author that has a collection of Books with property publishedDate.
Each Author has a collection books and they are mapped like so:
public class Author {
@Id
private Long id;
...
0
votes
1
answer
28
views
How to map from iterable to non iterable & vice versa using MapStruct
I have two classes - GeneralModel & HotelInfo as shown below.
I wanted to map from HotelInfo to GeneralModel && from List<HotelInfo> to GeneralModel .
HotelDomain has exactly same ...
2
votes
1
answer
444
views
Javax dependency in mapstruct generated file after upgrading to spring boot 3
I was tasked with upgrading one rest service in our hub so that it uses spring boot 3. Among others, I removed all javax imports and substituted them with jakarta imports instead.
But when I maven ...
1
vote
1
answer
180
views
In MapStruct, how do I use the same method parameter in @Mapping and a @Named method?
I have the following methods in my @Mapper class:
@Mapping(source = "localCar.color", target = "color")
@Mapping(source = "blueBookCar.price", target = "price")
...
0
votes
0
answers
42
views
How to instrument correct handling of null source values, when target is custom container (i.e. not List, Map, Optional)?
We use MapStruct 1.5.3 for class mapping between several layers. One layer has 'simple' properties (i.e. int, Integer, BigDecimal, String), the other container properties, where the containers has ...
0
votes
1
answer
50
views
How do I map a target to a source Map field having different parameterized types using MapStruct?
I want to use MapStruct to map from my Car to CarDto objects. The problem is that Car and CarDto have different parameterized types for their java.util.Map field. And that's because I want a simple ...
0
votes
1
answer
33
views
Mapstruct - how to create generated code to add when we have many to many entity
I try use mapstruct to save my DTO to entity. In the basic relations I had no problem with the generated code, but needs help with the generation in the relation many to many.
My entity:
Hero
@...
1
vote
0
answers
37
views
Auto generated MapperImpl class returns an entity instead of null
I am writing patchMutation() in which I use the map method, but in auto-generated MapperImpl class I can see it returns an entity instead of null:
PersonEntity mapToPatch(PersonInput input, @...
0
votes
0
answers
32
views
TransientPropertyValueException in Mapstruct created entities
Can anyone give a hint what can go wrong with saving two related entities to database.
The only problem is that these entities created out from data transfer objects with help of MapStruct.
Testcase ...
0
votes
0
answers
186
views
Mapstruct is unable to map into multiple levels of nested objects
I'm using MapStruct version 1.4.2, Java 17 and Spring-boot 3.1.0.
Here I'm trying to map into a nested object by passing source to the mapper method as below.
public class PackageProgress {
...
0
votes
2
answers
277
views
How to fix error: Couldn't find any of the CDI or Jakarta CDI Dependency types. Are you missing a dependency on your classpath?
I upgraded my entity library to Hibernate 6.2.7 from version 5.6.15. Added some new DTOs and Mapstruct mappers. Suddenly I am getting following error:
error: Couldn't find any of the CDI or Jakarta ...
0
votes
0
answers
111
views
Mapstruct null checking target field for no reason
I have the following class structure -
@Getter
@AllArgsConstructor
@Builder(toBuilder = true)
@ToString
@NoArgsConstructor
public abstract class ParentDTO {
String type;
List<String> tags;
}
@...