mapstruct

mapstruct: update existing field of entity using data from DTO

£可爱£侵袭症+ 提交于 2021-02-07 14:32:20
问题 I recently added mapStruct in my project. This framework is cool, but I can not figure out one thing. This is my case: I have Profile entity and field with the Person type. I want to update it using ProfileDto . I am using void fromDto(ProfileDto dto, @MappingTarget Profile entity) method for this. The problem is that mapper always create new Person instead of using person from profile entity My entity is: public class Profile { private Person person; .. setters, getters and constructors }

MapStruct Mapper as Spring Framework Converter - idiomatic use possible?

丶灬走出姿态 提交于 2021-02-04 13:08:23
问题 I'd like to combine MapStruct mappers with Spring's Conversion model. So I declare every Mapper interface as an extension of Spring's Converter : @Mapper public interface CarMapper extends Converter<Car, CarDto> { @Override CarDto convert(Car car); } I can then use the mapper beans by injecting the standard ConversionService : class CarWarehouse { @Autowired private ConversionService conversionService; ... public CarDto getCarInformation(Car car) { return conversionService.convert(car, CarDto

Mapstruct AnnotationProcessor with IntelliJ and Gradle

给你一囗甜甜゛ 提交于 2021-01-29 20:15:56
问题 I am trying to get the Mapstruct annotation processor to work in IntelliJ in a Gradle project. Ideally, I would expect for all configuration to be in the gradle-file and that anyone could just import the project into IntelliJ and get a complete setup without having to set any preferences manually. But I am okay with compromises on that. I am using IntelliJ 2018.3 and Gradle 5.0 with Java 11 (i.e. the latest and greatest). The Mapstruct version is 1.2.0.FINAL. What I have done: Configured the

Is it possible to convert HashMap in java to List using MapStruct?

▼魔方 西西 提交于 2021-01-28 08:14:09
问题 We are trying to find a way to convert HashMap to List using mapstruct but there is no such help on the internet. Does anyone know a way to do it using mapstruct? We have tried defining abstract class and use Abstract mapping but nothing works @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.WARN, implementationPackage = "com.mapstruct.mapper.impl") public abstract class OrderLineMapper { public com.internal.epfo.v1.OrderLine toOrderLineList(Map.Entry<Integer,

How can i combine Guice and Mapstruct?

若如初见. 提交于 2021-01-28 05:50:34
问题 I'm using jersey and Guice DI and I want to use Mapstruct interfaces with @Inject annotation. So is there some way to force Guice to autowire Mapstruct interface implementations ? 回答1: You can configure the implementations of the Mappers to be annotated with JSR 330 annotation by using @Mapper(componentModel = "jsr330") . You can find more information in the reference documentation. You can then bind the Mapper interface with the implementation class in your modules. One way to bind them is

Mapstruct generated class uses Lombok builder from parent instead of child

半世苍凉 提交于 2021-01-27 23:22:11
问题 I have class A (domain class), class B (mongo db repository layer class) extends A and both of them have Lombok @Builder on them. I need to convert between them and when I use Mapstruct for this, the implementation conversion class uses Builder from A when generating object of type B. This results in build failure due to "incompatible types". How to fix this? @Builder class A { } @Document @Builder class B extends A{ } @Mapper public interface ClassMapper { B mapToDocument(A domainObject); }

Mapstruct generated class uses Lombok builder from parent instead of child

老子叫甜甜 提交于 2021-01-27 21:57:11
问题 I have class A (domain class), class B (mongo db repository layer class) extends A and both of them have Lombok @Builder on them. I need to convert between them and when I use Mapstruct for this, the implementation conversion class uses Builder from A when generating object of type B. This results in build failure due to "incompatible types". How to fix this? @Builder class A { } @Document @Builder class B extends A{ } @Mapper public interface ClassMapper { B mapToDocument(A domainObject); }

Architecture Domain Model and View Model

和自甴很熟 提交于 2021-01-27 19:40:22
问题 I am trying to build application by spring boot and Domain Driven Design. I have a problem about Domain model (match with fields of table DB) and View Model (response API). Domain Model: EX: class Name @Getter @NoArgsConstructor @AllArgsConstructor class Name { String value; } class Product @Getter @NoArgsConstructor @AllArgsConstructor class Product{ Name name; } ViewModel: @Data @NoArgsConstructor @AllArgsConstructor class ProductView { //int prodId; String prodName; } Select data DB by

MapStruct: How to pass input object to expression?

烂漫一生 提交于 2021-01-27 16:37:37
问题 In MapStruct version 1.1.0.Final, this was possible.... @Mappings({ @Mapping(target = "transaction.process.details", expression = "java(MappingHelper.mapDetails(request))"), //more mappings }) Response requestToResponse(Request request); It was possible, since the mapDetails method was (by coincidence?) generated into the requestToResponse method. That's why request was not null. Now, since 1.1.0.Final didn't work with Lombok, I had to upgrade to 1.2.0.CR2. With this version, the mapDetails

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

两盒软妹~` 提交于 2021-01-05 05:56:11
问题 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