mapstruct

Mapstruct - How can I inject a spring dependency in the Generated Mapper class

家住魔仙堡 提交于 2020-07-31 19:08:13
问题 I need to inject a spring service class in the generated mapper implementation, so that I can use it via @Mapping(target="x", expression="java(myservice.findById(id))")" Is this applicable in Mapstruct-1.0? 回答1: It should be possible if you declare Spring as the component model and add a reference to the type of myservice : @Mapper(componentModel="spring", uses=MyService.class) public interface MyMapper { ... } That mechanism is meant for providing access to other mapping methods to be called

Prevent Cyclic references when converting with MapStruct

你说的曾经没有我的故事 提交于 2020-05-27 04:32:42
问题 Today I started using MapStruct to create my Model to DTO converters for my project and i was wondering if it handled cyclic references automatically but it turned out it doesn't. This is the converter i made to test it: package it.cdc.snp.services.rest.giudizio; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import org.springframework.stereotype.Component; import it.cdc.snp.dto.entita.Avvisinotifica; import it

Prevent Cyclic references when converting with MapStruct

最后都变了- 提交于 2020-05-27 04:32:08
问题 Today I started using MapStruct to create my Model to DTO converters for my project and i was wondering if it handled cyclic references automatically but it turned out it doesn't. This is the converter i made to test it: package it.cdc.snp.services.rest.giudizio; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import org.springframework.stereotype.Component; import it.cdc.snp.dto.entita.Avvisinotifica; import it

Map a dto to an entity retrieved from database if Dto has Id using MapStruct

安稳与你 提交于 2020-05-23 04:54:17
问题 I'm using MapStruct to make dto <-> entity mapping. The same mappers are used to create and update entities from dtos. A verification of the dto's id is done to know whether a new entity must be created (id == null) or it should be retrieved from database (id != null) . I'm actually using MapperDecorator as a workaround. Example : Mapper @Mapper @DecoratedWith(UserAccountDecorator.class) public interface UserAccountMapper { UserAccountDto map(User user); User map(UserAccountDto dto); User map

mapstruct mapping Entity OneToMany to DTO and reverse

我的未来我决定 提交于 2020-04-16 04:41:29
问题 I'm trying to use a mapstruct and I need to mapping Entity with a sub Entity list, I have relationship oneToMany and manyToOne and I need to mapping in both cases: @Data @Entity public class EmailEntity { private int id; ... // some fields @ManyToOne private DeliveredEmailInfoEntity deliveredEmailInfo; } . @Data @Entity public class DeliveredEmailInfoEntity { private int id; ... // some fields @OneToMany private List<EmailEntity> emails; } mapping to: @Data public class EmailDTO { private int

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

拈花ヽ惹草 提交于 2020-02-03 10:49:53
问题 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