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
-1
votes
1 answer

How to form date and time in Java

I'm using LocalDateTime.now() and OffSetDateTime.now() to retrieve the date and time but it's not the desired format. Does anyone know how to format this format? "2022-05-20T11:22:10" I'm using MapStruct to do request and response…
ner
  • 173
  • 1
  • 1
  • 9
-1
votes
2 answers

Mapping fields of List to fields of a single Object

Suppose, I have a List of cats like this: [Cat[name="Minnie", age=3], Cat[name="Pixie", age=1], Cat[name="Kazy", age=5]] And an Object Cats with fields: class Cats { int MinnieAge; int PixieAge; int KazyAge; } What is the best way to map the ages…
Karnimani
  • 23
  • 5
-1
votes
1 answer

@Value not working as expected in mapper abstract class

So I have a mapstruct mapper in my app, which has source to destination pojo mappings. I perform some logic inside the @AfterMapping class using the value from the @Value like below. But it seems like the value is not being fetched and hence its set…
ghostrider
  • 2,046
  • 3
  • 23
  • 46
-1
votes
1 answer

How to use the mapping in practice?

The example here: https://github.com/mapstruct/mapstruct-examples/blob/3457f37c24ea7799b0752cc7ee8307283ab09ad2/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java The generated mapping will be like: Employee…
cviniciusm
  • 139
  • 1
  • 2
  • 13
-1
votes
1 answer

MapStruct generates invalid mapper

I got the following two classes (I'm trying to map from 1st to 2nd): @Data @AllArgsConstructor @NoArgsConstructor public class RegisterRequestDto { private String username; private String firstName; private String lastName; private…
nevermindhf
  • 19
  • 1
  • 5
-1
votes
2 answers

How to get element of List in target(for mapping) if source doesn't contain this list?

I'm trying to map next structure(succesfully map in dozer, have some problems with mapstruct) list is absent in source, how can I get its first element in mapper? Target class: @Data public class FirstLvl { protected List
ovod
  • 49
  • 1
  • 7
-1
votes
1 answer

How can I change a value of an id attribute to its equivalent description in DTO class using mapstruct

I have a 1 entity class PersonEntity and corresponding to that I have Dto class @Entity(value="person") class PersonEntity{ String name; String id; } **DTO** class PersonDto{ String name; String id; String desc; (This is a lookup from a map…
-1
votes
1 answer

Spring-boot, How to replace the id value to the respective entity's any desired field name?

I am working on an existing database and I am not allowed to modify any table. I have the following entity: PostCharge Entity @Entity @Data // from lombok @AllArgsConstructor // from lombok @NoArgsConstructor // from lombok public class postCharge…
dsnewguy
  • 43
  • 11
-1
votes
3 answers

MapStruct. Map from List to List
Source sourceDto { List ids; } Target targetDto { List myObjects; } Custom Object CustomObject { Integer id, String name, String slug } Note I am using an external API that always need name and slug initialised to an…
tufac2
  • 668
  • 6
  • 7
-1
votes
2 answers

Map source class to a target field

I'm working on spring boot application where, I have two classes namely A and B. @Data class A{ int id; String name; } @Data class B{ int bId; A a; } I need to map a field of class B which is a using mapstruct. How to map a source class A to…
vinter
  • 466
  • 1
  • 3
  • 13
-1
votes
1 answer

Mapstruct - Prepare a list from a group of fields from the source object and set it to target object

I am getting the following flat structure from mongo db document as in source object and I need to group a few fields based on a pattern to prepare an arraylist and set it to the target object. { "_id": 1, "clientId": "1001", "grant1Id":…
mayur tanna
  • 241
  • 1
  • 3
  • 14
-1
votes
1 answer

mapstrcut - deactivated automatic mapping

I want to map an int to string with a specific mapping, but mapstrcut always converts automatically from int to string using String.valueOf, how can i deactivated this auto mapping ? @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) public…
Aymen Kanzari
  • 1,765
  • 7
  • 41
  • 73
-1
votes
1 answer

map struct interface error in SpringBoot with kotlin

i converted java spring boot codes to kotlin, now i have error in map struct interface and bean config class This is my Mapper interface @Component @Mapper interface PersonMapper { fun toPerson(personDTO: PersonDTO?): Person? fun…
Asoodeh
  • 19
  • 2
-1
votes
1 answer

How can i recursivelry convert Long to LocalDateTime with mapStruct?

I try to convert one complex object to another complex object. All the object have sub-object. In theses object, i have date with differents format... Look at that : ObjectA : { Long dateA, CustomObject: { Long dateB List
Jérémy
  • 391
  • 2
  • 7
  • 20
1 2 3
96
97