mapstruct

MapStruct requires Impl class

南楼画角 提交于 2019-12-03 11:32:20
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 private UserOSType userOsType; public DeviceTokens() {} public DeviceTokens(String tokenName, UserOSType

MapStruct ignore automatically unmapped properties

送分小仙女□ 提交于 2019-12-03 10:34:24
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 would take a lot of code to ignore each single property in each mapper class. I also do not want this

Set parent target to null if source is null in MapStruct

杀马特。学长 韩版系。学妹 提交于 2019-12-02 18:56:41
问题 I have the following Mappings @Mappings({ @Mapping(source = "id", target = "id"), @Mapping(source = "childId", target = "child.id") }) Entity objectDtoToEntity(ObjectDTO objectDTO); How could I configure my Mapper or Mappings so when I have childId as null the target Entity.child would be set null not Entity.child.id? 回答1: Found not a very elegant solution as for me but working solution. First change interface to abstract class then add @AfterMapping @Mappings({ @Mapping(source = "id", target

Set parent target to null if source is null in MapStruct

偶尔善良 提交于 2019-12-02 07:34:48
I have the following Mappings @Mappings({ @Mapping(source = "id", target = "id"), @Mapping(source = "childId", target = "child.id") }) Entity objectDtoToEntity(ObjectDTO objectDTO); How could I configure my Mapper or Mappings so when I have childId as null the target Entity.child would be set null not Entity.child.id? Found not a very elegant solution as for me but working solution. First change interface to abstract class then add @AfterMapping @Mappings({ @Mapping(source = "id", target = "id"), @Mapping(source = "childId", target = "child.id") }) public abstract Entity objectDtoToEntity

Lazy loading not working in JPA with hibernate

China☆狼群 提交于 2019-12-02 07:05:58
I am using JPA with hibernate in my spring boot application. Whenever I try to fetch the enities using jpa methods, its returning the entity plus all the association present inside it. I wanted to fetch the associated entities on demand(lazy loading), so I have provided fetch=FetchType.LAZY in my domain class. But still its returning all the entries. Below is the code: Case.java @Entity @Table(name="smss_case") public class Case implements Serializable { /** * */ private static final long serialVersionUID = -2608745044895898119L; @Id @Column(name = "case_id", nullable = false) @GeneratedValue

How to map JAXB elements annotated with @XMLSeeAlso using mapStruct?

痴心易碎 提交于 2019-12-01 13:57:05
I'm trying to map a bean which has some JAXB elements like @XmlSeeAlso, @XmlElement, @XmlSchemaType as properties for that class. @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Customer") @XmlSeeAlso({PersonalCustomer.class, BusinessCustomer.class}) public class Customer extends Role { @XmlElement(name = "AMLLineOfBusiness") private LOB amlLineOfBusiness; // 50 odd properties //some properties with XmlElement/XmlSchemaType // getters and setters } @Mapper public interface CustomerMapper { PersonalCustomer personcalCustomerToPersonalCustomer(PersonalCustomer pc); @Mappings({ /*Several

How to map JAXB elements annotated with @XMLSeeAlso using mapStruct?

流过昼夜 提交于 2019-12-01 13:09:17
问题 I'm trying to map a bean which has some JAXB elements like @XmlSeeAlso, @XmlElement, @XmlSchemaType as properties for that class. @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Customer") @XmlSeeAlso({PersonalCustomer.class, BusinessCustomer.class}) public class Customer extends Role { @XmlElement(name = "AMLLineOfBusiness") private LOB amlLineOfBusiness; // 50 odd properties //some properties with XmlElement/XmlSchemaType // getters and setters } @Mapper public interface

Spring boot Mapstruct StackOverFlow Error

放肆的年华 提交于 2019-12-01 06:44:40
I'm using mapstruct to map my entity and dto classes... I'm having problem with a loop on my mapper class... I have no ideia what to do... This is my mapper classes @Mapper(componentModel = "spring", uses = {BrandMapper.class}) public interface VehicleTypeMapper { VehicleTypeDTO vehicleTypetoVehicleTypeDTO(VehicleType vehicleType); Iterable<VehicleTypeDTO> vehicleTypetoVehicleTypeDTO(Iterable<VehicleType> vehicleTypes); VehicleType vehicleTypeDTOtoVehicleType(VehicleTypeDTO vehicleTypeDTO); } @Mapper(componentModel = "spring", uses = { VehicleTypeMapper.class, ModelMapper.class }) public

MapStruct and Lombok not working together

寵の児 提交于 2019-11-28 06:47:17
Tech Stack being used : Java 8 MapStruct : 1.2.0.Final Lombok: 1.16.18 IDE: IntelliJ - Lombok Plugin already installed Initially, I faced issues when I removed getters and setters and added @Getter and @Setter annotation, mapstruct is not able to find the property and says: Unknown property "id" in result type com.vg.once.dto.OneDto. Did you mean "null"? I came to know that Lombok 1.16.14 or newer along with MapStruct 1.2.0.Beta1 or newer are compatible and can work together, but my versions are newer then the desired still the issue is arising. One more solution that I have already tried is

MapStruct and Lombok not working together

戏子无情 提交于 2019-11-27 01:13:55
问题 Tech Stack being used : Java 8 MapStruct : 1.2.0.Final Lombok: 1.16.18 IDE: IntelliJ - Lombok Plugin already installed Initially, I faced issues when I removed getters and setters and added @Getter and @Setter annotation, mapstruct is not able to find the property and says: Unknown property "id" in result type com.vg.once.dto.OneDto. Did you mean "null"? I came to know that Lombok 1.16.14 or newer along with MapStruct 1.2.0.Beta1 or newer are compatible and can work together, but my versions