Skip to content

Conversation

hduelme
Copy link
Contributor

@hduelme hduelme commented Dec 13, 2023

I added support for Map as MappingSource.
If only Map<String, ?> as a valid source is present, unmapped target warnings/errors are suppressed. This fixes #167
I also added an inspection if the Map is raw or does not have a String as a key, like described in MapToBeanRawMapMapper and in MapToBeanTypeCheckMapper. For this I added two fixes, add <String, String> if the Map is raw and replace the key with String if the key is not of type String.

Copy link
Contributor

@thunderhook thunderhook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry it took so long. I had a look and just made a few nitpicks.

@filiphr
Copy link
Member

filiphr commented Dec 27, 2023

Thanks for your work on this @hduelme and thanks for the review @thunderhook.

I also had a look. I think that the inspection should be on the warning level by default, in order to be aligned to what we are doing in the processor. Apart from that I think we need to be a but more lax, e.g. in the MapToBeanRawMapper and MapToBeanTypeCheckMapper if you add a target parameter matching the map then it would work. Also if you have a look at MapToBeanNonStringMapAsMultiSourceMapper you'll see that it is possible to use non string map as a source if the source matches the target mapping.

@hduelme
Copy link
Contributor Author

hduelme commented Dec 28, 2023

@filiphr, @thunderhook, thanks for the feedback.
I've fixed the typos, removed the unused intention, and used lowercase string in the properties file.
I also switched the default level to WARNING for FromMapMappingMapTypeInspection. Additionally, I disabled the inspection if the name of the map parameter matches a target parameter or if the map parameter is used in a source mapping. The inspection only runs if the map parameter is the only source parameter and is not used for mapping directly.

For the UnmappedTargetPropertiesInspection I changed the check so that the inspection is disabled if the key of one map parameter is of type string. One thing I found during the investigation is that maps, arrays, and iterables are currently not recognized as source parameters when used as method parameters. The correct behavior would be to use the method parameter name as a source.

@filiphr filiphr merged commit f602c3a into mapstruct:main Jan 28, 2024
@filiphr
Copy link
Member

filiphr commented Jan 28, 2024

Thanks @hduelme. Sorry that it took me a bit to review it and merge it.

One thing I found during the investigation is that maps, arrays, and iterables are currently not recognized as source parameters when used as method parameters. The correct behavior would be to use the method parameter name as a source.

I am not sure that I understand what you meant with this. However, feel free to create an issue and a fix if you know what the bug is.

@hduelme
Copy link
Contributor Author

hduelme commented Jan 28, 2024

No problem. Thanks for having a look at this @filiphr
I will open a bug and provide a example for the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable unmapped target property warnings when implicitly mapping from a map
3 participants