GeezerVison is showing github.com — Conversion of BigDecimal to primitive double wrong with 1.5.2 · Issue #2913 · mapstruct/mapstruct
Conversion of BigDecimal to primitive double wrong with 1.5.2 #2913ActivityZegveld commented on Jun 29, 2022 Here is the analysis:
available method to use:
default Long mapAmount(BigDecimal amount) {
return amount.movePointRight(2).longValue();
}
Reason
As it is legal to assign a long to a double, mapstruct will use this method because it is user defined.
Generated code
1.4.2
simpleDestination.setRoundingDiff( source.getRoundingDifference().doubleValue() );
1.5.2
simpleDestination.setRoundingDiff( mapAmount( source.getRoundingDifference() ) );
work around
Use qualifiers to mark the mapAmount method as one specific for certain mappings and use qualfiedBy there to link them.
What will we do about this
I think this is also related to: #2840 and #1216
Because if we pick the exact match, there might be a better workaround by manually creating the default double map(BigDecimal decimal) method.
@filiphr: WDYT ? filiphr commented on Jun 30, 2022 Thanks for the analysis @Zegveld. This is most definitely related to #2840 and #1216. We'll need to figure out what actually broke this behaviour.
I think that we need to fix this inconsistency, because mapping from BigDecimal to double shouldn't use BigDecimal to long. filiphr commented on Aug 21, 2022 After doing some analysis on this one and #2849 it seems like the work we did in #2320 broke this. I still need to analyse why this happened. This was not supposed to happen when we did that PR. What do you think @sjaakd? It feels like the fact that the return type can be assigned to the expected type is causing the problem. filiphr commented on Sep 26, 2022 I am happy to announce that we have managed to find the root cause for this problem and we have a pending fix in #3032 Reacted by Silvio Wangler and Urs Wiss
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|