mapstruct

Can I create a DeepCopy of an Java Object/Entity with Mapstruct?

丶灬走出姿态 提交于 2021-01-05 05:52:08
问题 I have a JPA entity (but this question is interesting in general) that consists of multiple child classes (aggregation). I need to create a new entry in the DB that is 90% identical to the existing one (a few business values and of course the IDs need to be different). As we need mapstruct for mapping between entity and TO I was thinking "Can mapstruct do this for me?" After Creating a deep copy I could simply update the remaining fields and persist the object. Writing a copy constructor by

Can I create a DeepCopy of an Java Object/Entity with Mapstruct?

半城伤御伤魂 提交于 2021-01-05 05:50:09
问题 I have a JPA entity (but this question is interesting in general) that consists of multiple child classes (aggregation). I need to create a new entry in the DB that is 90% identical to the existing one (a few business values and of course the IDs need to be different). As we need mapstruct for mapping between entity and TO I was thinking "Can mapstruct do this for me?" After Creating a deep copy I could simply update the remaining fields and persist the object. Writing a copy constructor by

MapStruct add a new calculated field to the dto

ぐ巨炮叔叔 提交于 2020-12-30 08:25:29
问题 I'm trying to map an entity Order to a OrderDTO using MapStruct. I want to add to OrderDTO a new field total , this field is not available in the original entity Order and should be calculated using the information available in the Order (order entries price, quantity, taxes...). I created a new field total in the OrderDTO and I'm trying to map it by adding a default method to the mapper interface: public interface OrderMapper { ... default BigDecimal orderToTotal(Order order){ return

Nested list mapping using MapStruct

这一生的挚爱 提交于 2020-12-29 07:38:05
问题 How can I do the bean mapping using MapStruct for the below scenario. class Source { private String sourceId; private List<Course> courses; //always returns only one course } class Course { private String courseName; private List<Student> students; } class Student { private String studentName; } class Target { private String targetId; private String subjectName; private List<Member> members; } class Member { private String memberName; } Now I want to map sourceId to targetId, courseName to

MapStruct Impl is not generating right mapping

别等时光非礼了梦想. 提交于 2020-12-15 03:47:12
问题 The qualifiedByName mapping is getting not generating right impl file. Code: HospitalMapper.java package com.company.tracker.hospitals.vo.mapper; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; import java.util.Date; import java.util.List; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.Named; import com.company.tracker.hospitals

How to inject guice dependency in mapstruct interface - java

时光怂恿深爱的人放手 提交于 2020-12-13 04:53:48
问题 My objects Public void Student(){ private string name; private int age; } Public void ClassRoom(){ private string roomNo; private Student student; //Student Object } Public void School(){ private string roomNo; private String student; //String student } I have an interface @Mapper(componentModel = "jsr330", unmappedTargetPolicy = ReportingPolicy.IGNORE, builder = @Builder(disableBuilder = true)) public interface TestjkMapper { @Named("convertObjToString") static String convertObjToString

How to inject guice dependency in mapstruct interface - java

半世苍凉 提交于 2020-12-13 04:53:08
问题 My objects Public void Student(){ private string name; private int age; } Public void ClassRoom(){ private string roomNo; private Student student; //Student Object } Public void School(){ private string roomNo; private String student; //String student } I have an interface @Mapper(componentModel = "jsr330", unmappedTargetPolicy = ReportingPolicy.IGNORE, builder = @Builder(disableBuilder = true)) public interface TestjkMapper { @Named("convertObjToString") static String convertObjToString