mapstruct

How to change the location of classes generated by MapStruct?

拟墨画扇 提交于 2019-12-08 06:46:09
问题 I am using MapStruct to generate the mapping between the JAXB classes and my domain classes. I am using gradle plugin as described in MapStruct official site. During the compilation process, the classes are generated in "build/generated/sources/apt/main". How can i change this location? I am not able to find any guide for gradle though there is a compiler flag to change it through ant script, but unfortunately it is not working for gradle Any help is appreciated. 回答1: This is not linked to

Can MapStruct do a deep deproxy of Hibernate Entity Classes

亡梦爱人 提交于 2019-12-08 02:03:54
问题 This is a common issue for web service developers who would like to return entity classes directly. Even if all the data I need is loaded there are still many uninitialized proxies and collections that I don't need. I would like for them to just return null and not throw a Lazy Load Exception. Basically I just want the POJO contract, however proxies and hibernate collections have to be purged to get that (unless there is some new way in hibernate that I don't know about). Can I use MapStruct

Set null to target using mastruct

纵饮孤独 提交于 2019-12-07 17:40:41
问题 I am using mapstruct and I am wondering if there are any ways to set null value for some target properties. For example, public class MySource { private String prop1; private String prop2; public MySource() { // Initialization. } // Getters - Setters. } public class MySourceDto { private String prop1; private String prop2; public MySourceDto() { // Initialization. } // Getters - Setters. } @Mapper public interface MySourceMapper { @Mappings({ @Mapping(target = "prop1", propertyToSetNull =

MapStruct: mapping from java.util.Map to Bean?

血红的双手。 提交于 2019-12-07 16:33:05
问题 I currently have a Map<String, String> that contains values in the form key = value and I would like to "expand" those into a real object. Is it possible to automate that with MapStruct and how would I do that? To clarify: The code I would write by hand would look something like this: public MyEntity mapToEntity(final Map<String, String> parameters) { final MyEntity result = new MyEntity(); result.setNote(parameters.get("note")); result.setDate(convertStringToDate(parameters.get("date")));

Map multiple source fields to same type target fields with Mapstruct

余生颓废 提交于 2019-12-07 01:06:00
问题 Consider the following POJOs: public class SchedulePayload { public String name; public String scheduler; public PeriodPayload notificationPeriod; public PeriodPayload schedulePeriod; } private class Lecture { public ZonedDateTime start; public ZonedDateTime end; } public class XmlSchedule { public String scheduleName; public String schedulerName; public DateTime notificationFrom; public DateTime notificationTo; public DateTime scheduleFrom; public DateTime scheduleTo; } public class

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

可紊 提交于 2019-12-06 19:38:26
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 stuff } } But that seems to do nothing (If I remove the @Named annotations it works, but it is also used

How to change the location of classes generated by MapStruct?

坚强是说给别人听的谎言 提交于 2019-12-06 14:55:07
I am using MapStruct to generate the mapping between the JAXB classes and my domain classes. I am using gradle plugin as described in MapStruct official site. During the compilation process, the classes are generated in "build/generated/sources/apt/main". How can i change this location? I am not able to find any guide for gradle though there is a compiler flag to change it through ant script, but unfortunately it is not working for gradle Any help is appreciated. This is not linked to MapStruct, but to the way the gradle apt plugin works and how it tells the Java compiler to place the

Can MapStruct do a deep deproxy of Hibernate Entity Classes

六月ゝ 毕业季﹏ 提交于 2019-12-06 08:33:35
This is a common issue for web service developers who would like to return entity classes directly. Even if all the data I need is loaded there are still many uninitialized proxies and collections that I don't need. I would like for them to just return null and not throw a Lazy Load Exception. Basically I just want the POJO contract, however proxies and hibernate collections have to be purged to get that (unless there is some new way in hibernate that I don't know about). Can I use MapStruct to do this? More details about this if needed: http://www.mojavelinux.com/blog/archives/2006/06

Nested Mapping in Mapstruct

徘徊边缘 提交于 2019-12-06 04:30:43
问题 I am new to MapStruct API, can anyone say how to do nested Mapping. I have two classes one is my actual purchaseOrder class, which is known my target class, the other is EDPurchaseOrder class which known as source file, here don't worry about the naming conventions I used, just go with source and target files. Source Classes Source class EDCustomerOrder and its reference classes public class EDCustomerOrder{ private Integer orderID; private String orderNumber; private BigDecimal orderTotalQty

Set null to target using mastruct

痴心易碎 提交于 2019-12-06 03:45:29
I am using mapstruct and I am wondering if there are any ways to set null value for some target properties. For example, public class MySource { private String prop1; private String prop2; public MySource() { // Initialization. } // Getters - Setters. } public class MySourceDto { private String prop1; private String prop2; public MySourceDto() { // Initialization. } // Getters - Setters. } @Mapper public interface MySourceMapper { @Mappings({ @Mapping(target = "prop1", propertyToSetNull = null)}) public MySourceDto toView(MySource mySource); } I would love the above source, dto and mapper to