mapstruct

How to tests and mock mapstruct converter?

痴心易碎 提交于 2021-02-11 14:21:50
问题 I use mapstruct frameword on my java gradle project and it works perfectly but i just want to test : mapstruct generated sources (converter) service class (call mapstrcut converter) I have try to use an other topic to do this but it not working for me. This is my mapstruct interface : @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface RisqueBOConvertisseur extends BOConvertisseur<RisqueARS, RisqueBO> { @Override RisqueBO convertirDaoVersBo(RisqueARS dao); @Override

How to tests and mock mapstruct converter?

落爺英雄遲暮 提交于 2021-02-11 14:21:10
问题 I use mapstruct frameword on my java gradle project and it works perfectly but i just want to test : mapstruct generated sources (converter) service class (call mapstrcut converter) I have try to use an other topic to do this but it not working for me. This is my mapstruct interface : @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface RisqueBOConvertisseur extends BOConvertisseur<RisqueARS, RisqueBO> { @Override RisqueBO convertirDaoVersBo(RisqueARS dao); @Override

How to inject(custructor) a spring bean into abstract mapper of Mapstruct?

北慕城南 提交于 2021-02-10 18:37:57
问题 I am having below mapper class in which I want to use CounterService . I am trying constructor injection but that's not working and null is printing. @Mapper(componentModel = "spring", uses = CounterService.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR) public abstract class CarMapper { private CounterService counterService; public CarMapper(CounterService counterService) { this.counterService = counterService; } public abstract Car dtoToEntity(CarDto carDto); public CarDto

Mapstruct to update values without overwriting

南楼画角 提交于 2021-02-10 05:11:42
问题 Is there a way to instruct MapStruct to not overwrite values in the target? For example: public interface IMyMapper { IMyMapper INSTANCE = Mappers.getMapper(IMyMapper.class); @Mappings({ @Mapping(target = "foo", source = "source.FOO"), @Mapping(target = "bar", source = "source.BAR2"), }) void updateTargetEntity(@MappingTarget MyTarget target , MySource source); } class MyTarget { String a; String b; ... } class MySource { String a; String b; ... } Where for instance target will have a = "asdf

MapStruct : Dealing with HashMap entries as source

寵の児 提交于 2021-02-09 08:11:33
问题 Here is my source object: public class Record { public final long captureTime; public final String environnement; public final String bundle; public final String type; public final String id; public final Map<String,Object> meta; } Here is my destination object: public class MappedRecord { public final long captureTime; public final String environnement; public final String bundle; public final String type; public final String id; public final String ip; public final String server; } And my

MapStruct : Dealing with HashMap entries as source

心不动则不痛 提交于 2021-02-09 08:08:51
问题 Here is my source object: public class Record { public final long captureTime; public final String environnement; public final String bundle; public final String type; public final String id; public final Map<String,Object> meta; } Here is my destination object: public class MappedRecord { public final long captureTime; public final String environnement; public final String bundle; public final String type; public final String id; public final String ip; public final String server; } And my

MapStruct : Dealing with HashMap entries as source

房东的猫 提交于 2021-02-09 08:05:30
问题 Here is my source object: public class Record { public final long captureTime; public final String environnement; public final String bundle; public final String type; public final String id; public final Map<String,Object> meta; } Here is my destination object: public class MappedRecord { public final long captureTime; public final String environnement; public final String bundle; public final String type; public final String id; public final String ip; public final String server; } And my

MapStruct : Dealing with HashMap entries as source

心已入冬 提交于 2021-02-09 08:04:17
问题 Here is my source object: public class Record { public final long captureTime; public final String environnement; public final String bundle; public final String type; public final String id; public final Map<String,Object> meta; } Here is my destination object: public class MappedRecord { public final long captureTime; public final String environnement; public final String bundle; public final String type; public final String id; public final String ip; public final String server; } And my

How can I map properties conditionally with MapStruct 1.2?

我们两清 提交于 2021-02-08 12:38:08
问题 Is it possible with MapStruct 1.2 to map a source property with a specific value to a specific different value in the target? I think about something like this: public abstract class JiraKpmMapper { @Mappings({ @Mapping(source = "mySource.propA", target = "myTarget.propX") }) @ValueMappings({ @ValueMapping(source = "ABC", target = "XYZ"), @ValueMapping(source = "123", target = "789") }) public abstract MyTarget source2Target(final MySource mySource); } So that when MapStruct sees during the

mapstruct: update existing field of entity using data from DTO

给你一囗甜甜゛ 提交于 2021-02-07 14:33: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 }