-
-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapping from Map to Map and specify source and target keys #3303
Labels
Comments
This is a valid request @JM92103, I don't see why something like this shouldn't be supported. However, I would expect the implementation to look like: public class MyMapperImpl implements MyMapper {
private final Map<String, String> fromCsvToStpTransactionKeyMappings;
public MyMapperImpl() {
this.fromCsvToStpTransactionKeyMappings = new HashMap<>();
this.fromCsvToStpTransactionKeyMappings.put( "Cash_Amount", "value" );
this.fromCsvToStpTransactionKeyMappings.put( "Date_Of_Money_Movement", "valueDate" );
}
@Override
public Map<String, String> fromCsvToStpTransaction(Map<String, String> rec) {
if ( rec == null ) {
return null;
}
Map<String, String> map = new LinkedHashMap<>( Math.max( (int) ( rec.size() / .75f ) + 1, 16 ) );
for ( java.util.Map.Entry<String, String> entry : rec.entrySet() ) {
String key = entry.getKey();
String value = entry.getValue();
map.put( this.fromCsvToStpTransactionKeyMappings.getOrDefault( key, key ), value );
}
return map;
}
} The I'll put this for "up for grabs" in case someone from the community is interested in working on this. |
thunderhook
added a commit
to thunderhook/mapstruct
that referenced
this issue
Aug 28, 2023
…keys (for Map<String, String>)
thunderhook
added a commit
to thunderhook/mapstruct
that referenced
this issue
Aug 28, 2023
thunderhook
added a commit
to thunderhook/mapstruct
that referenced
this issue
Aug 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case
I have a use case where I need to convert a Map<String, String> to a Map<String, String> but manipulate the keys. Currently I am trying to do
But the generated code is ignoring these values and just doing a basic Map conversion like below
Generated Code
I would expect the generated code to look something like
Possible workarounds
No response
MapStruct Version
1.5.5
The text was updated successfully, but these errors were encountered: