Java / MapStruct Java Interview questions part 2
How does MapStruct map a Map to another Map type?
Declaring a method with Map parameter and return types tells MapStruct to generate a loop over entrySet(), mapping each key and each value individually and putting the results into a new map instance.
@Mapper public interface ScoreMapper { Map<String, Integer> toIntScores(Map<String, String> raw); }
If the key or value types differ (as in the example, String values becoming Integer), MapStruct applies its normal type-conversion rules to each - using built-in conversions like Integer.parseInt, a default method you provide, or another mapper method if one matches. Keys and values are converted independently of each other.
More Related questions...