Sergey Plotnikov
Sergey Plotnikov

Reputation: 322

Unmapped target property warning when property name starts with "set"

I'm trying to implement a mapping between an entity and DTO using MapStruct. One of the properties to be mapped is "settlementDate". It has the same name in DTO class and the mapping works, but I get the following warning during the compilation:

/path/to/project/SomeDataMapper.java:15: warning: Unmapped target property: "tlementDate".
    SomeData toEntity(SomeDataDTO someDataDTO);

Is there any way to make MapStruct deal with such a weirdly named property without warnings?

I've tried using @Mapping annotation to specify the names explicitly, but this didn't help:

@Mapping(target = "settlementDate", source = "settlementDate")
SomeData toEntity(SomeDataDTO someDataDTO);

Upvotes: 1

Views: 3792

Answers (2)

Filip
Filip

Reputation: 21403

I would say that this is a bug, the name is not that weird 😀. Can you please create an issue in the bug tracker (if you haven't already)

For the time being you can try and "use" the wrong property mapping. Something like:

@Mapping(target = "tlementDate", source = "settlementDate")
SomeData toEntity(SomeDataDTO someDataDTO)

Upvotes: 1

Ehcnalb
Ehcnalb

Reputation: 476

Your problem comes from the name "settlementDate", apparently since the generation it's considered like a setter and not a variable. So I suggest to you :

 @Mapping(target="settlementDate",source="settlementDate", qualifiedByName="methodName")
 SomeData toEntity(SomeDataDTO someDataDTO);

 @Named("methodName")
 default ... methodName2(... settlementDate){
     //your transformation to get settlementDate of SomeData from settlementDate from SomDataDTO
 }

I haven't tried with a name beginning with "set", else it's working

Upvotes: 0

Related Questions