-
-
Notifications
You must be signed in to change notification settings - Fork 979
Support for Mapping from Map<String, ???> to Bean #1075
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
Comments
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 |
@gunnarmorling I am not sure that we will need to do something special to support mapping from We already have a mechanism that allows us to map |
I've tried to do it in the following way: @Mapping(expression = "java(parameters.get(\"name\"))", target = "name")
public MyEntity mapToEntity(final Map<String, String> parameters); But is it possible to convert the value if the MyEntity.name type is boolean (without calling Boolean.parse(...) manually)? |
I have a similar requirement now, and I need to directly map the map to the bean. I don't know if there is any information on the advancement of this function or if there are other solutions? |
We have this requirement too. However, for us it is important that this Map to Object mapper would behave in a PATCH manner, updating only the object fields that are provided in the map and ignoring the rest. Is that also the intention of this feature? |
@markbanierink the idea for this feature is to support all the other functionalities that MapStruct has. So if you are using We have not yet discussed the length of the implementation, but I envision that it would generate something like:
Of course with proper conversions. |
Will it be possible to map a map with a nested map?
and refere it like
|
I saw that there was a beta release for 1.4.0. I am constantly stalking this issue because it would really be a great help to have this feature on 1.4.0. Is there any change that this feature makes it into the release? |
Whether this will make it into the final release or not depends on the time we have to implement it or not. There is PR #1744 with some initial steps, but it is not ready. Anyways if this does not make it into the final release we will try to include it in the next one. This is one of the most requested feature and I agree that it makes sense to have support for this. We need to iron out the implementation, since I want to support We are also aware that we've been rather slow in doing new releases and that's mostly because of lack of time. We are trying to improve on this and release more frequently in the future. |
Hi i could probably help with the lack of time problem :-) I would be glad to file a pull request on this but i was confused about the state of this issue because of the existing pull request and the duplicates. The pull request now also seems to be closed. Could you clarify the state here? Is there any usable code to get closer to the solution? Or could i start over with a completely pull request? |
Hi, i just wanted to check if there is any progress on this topic i am really looking forward to this feature |
@ckosmowski no.. there's not any progress on this issue. I planned to work on it, but got side-tracked in a few other issues. |
Okay thanks. I'd like to know what you think about an approach i was thinking about looking at the code. Keeping in mind that the BeanMappingMethod class and its post processing has plenty of features already i was thinking about the following approach:
What do you think? |
I guess that was the original idea that I came up with as well. The history of this PR probably shows. Anyway. We (@filiphr and myself) decided not to pursue the 'WrapperBean' idea and instead copy the One of the biggest drawback was that it requires to construct an additional class runtime (performance), but also keeping track of that class for reuse in other mappings. |
Okay, did you start with that already or should i give it a try? :-) |
Didn't do anything substantially. So give it a shot. If you require any
advice I'll try to be of assistance.
Op di 29 dec. 2020 14:24 schreef Chris <[email protected]>:
… Okay, did you start with that already or should i give it a try? :-)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1075 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABPDEY7AE6HFTTQQXSGFJE3SXHKA3ANCNFSM4DAF6A4Q>
.
|
I didn't know that this would be shown here directly. But as you can see, i gave it a try. I tried a slightly different approach. When i tried to copy BeanMappingMethod i realized that this would result in heavy code duplication now and in the need to implement every feature twice in the future, so i tried to add a new Type of Unfortunately i was not able to the full maven pipeline and integration tests running. The build complains about circular dependencies. A review would be appreciated. Is this a promising approach or rather something to throw away? :-) https://github.com/ckosmowski/mapstruct/tree/issues/1075 EDIT: Seems like i managed to remove the circular package dependency, looks better now |
Hey Chris, your solution looks surprisingly simple to me 😄 . Could you make a PR out of this, so that also @filiphr can have a look at the implementation as well. I did make a PR for it in the past (its still there open for inspiration 😄 ). I guess the best thing you could do at this moment is to invest in unit tests.. With that I mean, all kinds of combinations of update methods, create methods, mapping strategies. Also I would like to to see what happens if you cannot make a direct mapping from a map to a target.. E.g. is an available mapping method / typeconversion called correctly? Perhaps its the obvious thing.. but unit test make up a lot of our invested effort and will prove valuable always. I do have some comments: e.g. I would expect different accessors than |
…or update method and default values, use default type for untyped maps
Any updates on this? We could really benefit from this in our current project :-) |
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 :-) |
You can seek to join the spring team, so that better compatible with Java, better promotion |
Co-authored-by: Filip Hrisafov <[email protected]>
Co-authored-by: Filip Hrisafov <[email protected]>
Refering to Stack-Overflow
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:
Essentially that should turn into code like this:
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.
The text was updated successfully, but these errors were encountered: