You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for Mapping from Map<String, ???> to Bean #1075
The situation is: I have a REST service that must be called with a huge amount of parameters (as by customer request) and those should be stored in a database. The easiest way to do that would be to take the parameter map and map that to an entity object. As it is about the same type of code to map from an object to and object or from a map to an object I assume it should not be too difficult to allow mapping like this:
public MyEntity mapToEntity(final Map<String, String> parameters);
It would be nice to have other variable types supported as well, like Map<String, Object>, but I am not sure at which point it becomes too complicated.
Reacted by buwoyouwo, askfor, Ferenc Czina, Flemming Harms, Igor Dmitriev, Evgeniy Azargaev, Brian Lenz, Marcel Overdijk, dharezlak, legrosc and 20 more
Yes, I've been thinking about this, too. There also is #717 which is related. It'd require quite some changes I reckon but I'd be sympathetic to adding this. For Map<String, Object> we'd need a new property on @Mapping for (optionally) specifying the type of the property in the map.
@gunnarmorling I am not sure that we will need to do something special to support mapping from Map<String, Object> into a bean. If you look at the map as a bean that has a getter that returns an Object, then it is not different than what we have now.
We already have a mechanism that allows us to map Object to B. The user will have to provide the mapping classes from Object to their respective types (something that needs to be done for String also). I am not sure how it'll work for the reverse type, but I think that it can be done in a similar way.
Actually in #2317 this is basically implemented and working. However like most of us because of the limited time i am granted to spend on open source projects during work time. It seems like there are still some unit tests missing, but unfortunately i am out of sprint time for this (for now). Whould you like to take over? Or maybe @sjaakd and @filiphr have the chance to finish it (Documentation?) We're almost there :-)
changed the title [-]Please add a feature to map from java.util.map to an object[/-][+]Support for Mapping from Map<String, ???> to Bean[/+]on Jun 27, 2021
Activity
gunnarmorling commentedon Feb 17, 2017
Yes, I've been thinking about this, too. There also is #717 which is related. It'd require quite some changes I reckon but I'd be sympathetic to adding this. For
Map<String, Object>we'd need a new property on@Mappingfor (optionally) specifying the type of the property in the map.filiphr commentedon Feb 18, 2017
@gunnarmorling I am not sure that we will need to do something special to support mapping from
Map<String, Object>into a bean. If you look at the map as a bean that has a getter that returns anObject, then it is not different than what we have now.We already have a mechanism that allows us to map
ObjecttoB. The user will have to provide the mapping classes fromObjectto their respective types (something that needs to be done forStringalso). I am not sure how it'll work for the reverse type, but I think that it can be done in a similar way.Raild commentedon Feb 21, 2017
I've tried to do it in the following way:
But is it possible to convert the value if the MyEntity.name type is boolean (without calling Boolean.parse(...) manually)?
mapstruct#1075 .. some vague ideas..
mapstruct#1075 .. some vague ideas..
mapstruct#1075 .. some vague ideas..
mapstruct#1075 refactoring source reference
mapstruct#1075 initial steps, reproducer and adapting propertymapping
mapstruct#1075 refactoring source reference
mapstruct#1075 initial steps, reproducer and adapting propertymapping
mapstruct#1075 refactoring source reference
mapstruct#1075 adapting sourcereference
mapstruct#1075 initial steps, reproducer and adapting propertymapping
30 remaining items
mapstruct#1075, renamed AccessorType (MAP_GET, MAP_CONTAINS), tests f…
mapstruct#1075, start unit tests the new way
mapstruct#1075, unit test with nested source
mapstruct#1075, add unit test for nested map in source bean
mapstruct#1075, forge map to bean method
mapstruct#1075, Add warning for untyped maps and for maps with non-St…
mapstruct#1075, checkstyle only
jishei-128 commentedon Apr 13, 2021
Any updates on this? We could really benefit from this in our current project :-)
ckosmowski commentedon Apr 13, 2021
Actually in #2317 this is basically implemented and working. However like most of us because of the limited time i am granted to spend on open source projects during work time. It seems like there are still some unit tests missing, but unfortunately i am out of sprint time for this (for now). Whould you like to take over? Or maybe @sjaakd and @filiphr have the chance to finish it (Documentation?) We're almost there :-)
ordisilent commentedon May 7, 2021
You can seek to join the spring team, so that better compatible with Java, better promotion
mapstruct#1075, Mapping from Maps to Beans -> Accessor approach
mapstruct#1075 Support for Mapping from Map<String, ???> to Bean
#1075 Support for Mapping from Map<String, ???> to Bean
[-]Please add a feature to map from java.util.map to an object[/-][+]Support for Mapping from Map<String, ???> to Bean[/+]