mapstruct

MapStruct equivalent of hint(Dozer)?

孤街醉人 提交于 2019-12-11 17:50:03
问题 In Dozer we are able to mention interfaces in hint during field mapping. How can we achieve the same in MapStruct ? I could not put the exact code here. But, it is the similar as below. We have here an Domain class example: Class A<T extends B> extends C<T> { ... }; Where, B is a abstract class. C is a class which contains a List item which we have to map. Similar is the structure of the classes and interfaces on DTO side. So, the mapping is as below in Dozer: <mapping> <class-a>Domain.A<

Mapstruct is not updating its getters and setters in the generated source files

纵饮孤独 提交于 2019-12-11 16:11:17
问题 I have an entity with a property I used to write like this private Long ICU; I'm using mapstruct: Here is my mapper for said entity: @Mapper(componentModel = "spring") public interface ProtectionQueryMapper extends EntityMapper<ProtectionQueryDto, Protection> { ProtectionQueryDto toDto(Protection protection); Protection toEntity(ProtectionQueryDto protectionQueryDto); List<Protection> toEntity(List<ProtectionQueryDto> protectionQueryDtos); List<ProtectionQueryDto> toDto(List<Protection>

mapping of non-iterable to iterable in mapstruct

白昼怎懂夜的黑 提交于 2019-12-11 15:11:40
问题 I am trying to map a non-iterable value i.e. String to a list of string using mapstruct. So I am using @Mapping(target = "abc", expression = "java(java.util.Arrays.asList(x.getY().getXyz()))") Here abc is List<String> xyz is a String But for this i need to check for null explicitly. Is there any better way of maaping a non-iterable to iterable by converting non iterable to iterable. 回答1: Here is an example for non iterable-to-iterable: public class Source { private String myString; public

MapStruct Retrieving from arrayList

醉酒当歌 提交于 2019-12-11 14:04:41
问题 I'm trying to use MapStruct to map two objects. I have been searching for a while and I haven't been able to find anything, though I'm new to programming so I'm sure it's easier than I'm making it. Here is some stripped back code (Note that the real code is more complex, with the child object from the arraylist not being the same type as the destination objects child variable as it is here): SourceObject public class SourceObject { public ArrayList<ListObject> list = new ArrayList<ListObject>

Mapping element of a list of different type with mapstruct

梦想与她 提交于 2019-12-11 04:48:39
问题 We are mapping a object that have a list of object that all implement a parent interface but may have a different implementation. But it seem when we are mapping the list only the value from ParentClass was mapped not the value from the child. But mapping directly the child workfine. public class ParentClass{ String name; int anotherParentField; List<ParentClass> relation; } public class ChildClass1 extends ParentClass{ String customCLass1Field; } public class ChildClass2 extends ParentClass

Can't map property when using MapStruct

折月煮酒 提交于 2019-12-10 16:45:59
问题 I am using MapStruct library to map objects but I got this error: Can't map property "java.util.Date aDate" to "javax.xml.bind.JAXBElement ADATE". Consider to declare/implement a mapping method: "javax.xml.bind.JAXBElement map(java.util.Date value)". My question: WHERE should I decleare this mapping method? 回答1: I solved this issue by writing another class: public class DateMapper { public JAXBElement<XMLGregorianCalendar> map(Date value) { // conversion here return atswer; } } and using this

Mapping an object to an immutable object with builder (using immutables annotation processor) in mapstruct

别说谁变了你拦得住时间么 提交于 2019-12-10 03:36:28
问题 We are using the immutables framework to generate all DTOs. Now we would like to map these objects one to another with mapstruct. But the generated DTOs are immutable and have no setters and no constructor, corresponding to the builder pattern. They are only filled through the corresponding builder accessed by a static builder() -method. We instead tried to map DTO1 to DTO2.Builder which would work if mapstruct would recognize the setter in the Builder but these do not have void return type

How to write Junit test for mapstruct abstract mapper injected via Spring

随声附和 提交于 2019-12-10 02:56:13
问题 I'm using MapStruct, mapstruct-jdk8 version 1.1.0.Final and defining abstract class that I inject via Spring. I'm looking at how to be able to test them via Junit Test ? I've basicaly a main mapper that will use 2 sub mappers @Mapper(componentModel = "spring", uses = {SubMapper1.class, SubMapper2.class}) public abstract class MainMapper { @Mapping(target = "field1", qualifiedByName = {"MyMapper2Name", "toEntity"}) public abstract MyEntity toEntity(MyDto pDto); public MyDto fromEntity(MyEntity

MapStruct ignore automatically unmapped properties

你。 提交于 2019-12-09 07:39:55
问题 I am using MapStruct with big models (more than 50 fields) shared between different business use cases in my code. Depending on the entry point, some properties will be mapped and some not. When I build my project, I will always get the "WARNING: Unmapped target properties" message. I have researched and seen that it is possible to tell the mapstruct to ignore the field by using the semantic @Mapping(target = "propName", ignore = true) The problem is, given my objects with so many fields, it

How to use @Qualifier or @Named with @AfterMapping in mapstruct?

笑着哭i 提交于 2019-12-08 07:20:25
问题 In their documentation (here: http://mapstruct.org/documentation/dev/api/org/mapstruct/AfterMapping.html), they mention that @AfterMapping can be used with @Qualifier / @Named to filter, but I can't find it anywhere how to actually use it this way. My best guess was to use it like this: @Mapper public abstract class CustomerMapper { @Named("Test") public abstract Customer map(CustomerDto dto); @Named("Test") @AfterMapping public void doAfterMapping(@MappingTarget Customer customer) { //do