mapstruct

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

感情迁移 提交于 2020-02-03 10:49:27
问题 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 succeeded on such integration? and if yes what can I be missing? My test started with something bigger, but when I realized it was not working I decided to use a smaller example, so this is what I did: Using openjdk-10.0.1_windows-x64 downloaded and

MapStruct requires Impl class

纵饮孤独 提交于 2020-01-12 07:05:55
问题 I have next classes: Mapper public interface DeviceTokensMapper { DeviceTokensMapper INSTANCE = Mappers.getMapper(DeviceTokensMapper.class); @Mappings({ @Mapping(source = "tokenName", target = "tokenName"), @Mapping(source = "userOsType", target = "osType"), }) DeviceTokensDTO toDeviceTokensDTO(DeviceTokens deviceTokens); } Entity: @Entity public class DeviceTokens { @Id @Column(name="token_name", nullable = false) private String tokenName; @Column(name = "os", nullable = false) @Enumerated

JUnit - How to mock MapStruct nested mapper

白昼怎懂夜的黑 提交于 2020-01-06 07:36:12
问题 I'm receiving an annoying NPE when I run a Unit Test for a service layer class. This class use an autogenerated mapper from MapStruct, which inside use another mapper (see in the Mapper annotation the "uses" attribute): Mapper(componentModel = "spring", uses = {UserMapper.class}) public interface CandidateMapper extends EntityMapper<CandidateDTO, Candidate> { @Mapping(target = "createdBy", ignore = true) @Mapping(target = "createdDate", ignore = true) @Mapping(target = "lastModifiedBy",

Mapstruct LocalDateTime to Instant

跟風遠走 提交于 2020-01-03 20:59:46
问题 I am new in Mapstruct. I have a model object which includes LocalDateTime type field. DTO includes Instant type field. I want to map LocalDateTime type field to Instant type field. I have TimeZone instance of incoming requests. Manually field setting like that; set( LocalDateTime.ofInstant(x.getStartDate(), timeZone.toZoneId()) ) How can I map these fields using with Mapstruct? 回答1: You have 2 options to achieve what you are looking for. First option: Use the new @Context annotation from 1.2

How to map nested collections using MapStruct?

蓝咒 提交于 2020-01-02 03:00:54
问题 I have 2 entities: Entity 1: public class Master { private int id; private Set<SubMaster> subMasters= new HashSet<SubMaster>(0); } public class SubMaster{ private int subId; private String subName; } Entity 2: public class MasterDTO { private int id; private Set<SubMaster> subMasters= new HashSet<SubMaster>(0); } public class SubMasterDTO{ private int subId; private String subName; } I am using MapStruct Mapper to map values of POJO to another. public interface MasterMapper{ MasterDTO toDto

Nested Target in MapStruct (Using Lombok) not working fluently

て烟熏妆下的殇ゞ 提交于 2019-12-24 19:16:19
问题 I am trying to use Mapstruct to do some nested mapping and with Lombok. As according to their latest specification mapstruct 1.2 works out of the box with Lombok. Here is my code: Source Classes @Builder @Getter @Setter public class PojoA { private String stringA; private int integer; private PojoB pojoB; } @Builder @Getter @Setter public class PojoB { private long aLong; private String string; private PojoC pojoC; } @Builder @Getter @Setter public class PojoC { private int value; } Target

How mapping to List<> with mapstruct

两盒软妹~` 提交于 2019-12-24 19:07:16
问题 Hi i need mappig variables to request. How can i mapp into List. My request looks like. public class Request { private String Id; private List<Data> applicationData; @Data @NoArgsConstructor @AllArgsConstructor public static class Data { private String data1; private String data2; private String data3; } } and my mapper @Mapper(componentModel = "spring") public abstract class RequestMapper { @Mapping(target = "Id", source = "data.Id") @Mapping(target = "data.???.data1", source = "data.data1")

MapStruct: Object.class to Custom.class mapping

安稳与你 提交于 2019-12-24 12:50:31
问题 I'm a newbie with MapStruct , and need some help with that. I have a Source class, with an attribute Object input; Which, in runtime, returns a custom object named TicketDetails. Now, in my target class there is a attribute named, MyTicket myTicket; which, I need to map with an attribute of TicketDetails object. For, better understanding, I'm writing the normal java code example below. SourceClassModel sourceClassModel = new SourceClassModel(); TargetClassModel targetClassModel = new

How to map only specified fields using mapStruct?

醉酒当歌 提交于 2019-12-23 09:56:12
问题 MapStruct is mapping all the properties of source and destination by default if they have same name. Although we can use ignore property in @Mapping for omitting any field mapping. But that's not I want. I want control over the mapping strategy. I've to specify something like @Mapper(STRATEGY=MAPPING_STRATEGY.SPECIFIED) public interface EmployeeToEmployeeDTOMapper { @Mappings({ @Mapping(target="id", source="id"), @Mapping(target="name", source="name") }) public EmployeeDTO

Mapstruct generated class not being injected by Spring in JHipster web app

拥有回忆 提交于 2019-12-22 04:42:55
问题 I'm developing a web app created with JHipster v2.20.0. Using Eclipse 4.5.0 WTP as IDE. The Spring configuration is annotation based. I've just merged this pull with our code. When I try to run the application inside Eclipse I get this exception: [INFO] com.app.tenancy.hibernate.MyCurrentTenantIdentifierResolver - MyCurrentTenantIdentifierResolver.getTenantId(): Couldn't find Company/Tenant for the domain inventario, stopping serving the request [WARN] org.springframework.boot.context