-
Notifications
You must be signed in to change notification settings - Fork 329
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
merging values passed in path params with deserialized values #953
base: master
Are you sure you want to change the base?
merging values passed in path params with deserialized values #953
Conversation
valuedParameter.setValue(value); | ||
} else { | ||
Object mergedValue = objectMerger.merge(existingValue, value); | ||
valuedParameter.setValue(mergedValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it isn't. I just did this to make it explicit. What do you think?
I guess there is a way to do this without having to add this extra dependencies... Theoretically you could use IOGI with an existing object, and only apply the request.getParameters() (path params) into this object. No need for merges. Do you wanna give a try? |
@lucascs We could try to do this with IOGI but we would need to guarantee the order of the observers. It depends on executing With the current CDI version we can't guarantee it. Maybe when CDI 2.0 is released we can change it and remove the |
It'd be great do not depend on the order of observers like this PR proposes. |
If you use this class from IOGI: construct it with VRaptorInstantiator, the request parameters and the deserialized object, you just use Something like this should work. |
Actually I didn't understand. Do you have any example of this being used? |
Take a look at the test: |
@lucascs but this Remembering that not only the first level should be handled. e.g.
We could use in our controller:
|
Not sure, try it please =) |
Ok! I'll give it a try and after it I'll give a feedback here! Thank you! |
Guys, I could not make this work with |
@nykolaslima sorry my delay. Before doing that I'll give a try to I'll be back with the result soon :) |
No problem. I'll wait for your response. Thank you!
|
@nykolaslima, You'll need to inject if (existingValue == null) {
valuedParameter.setValue(value);
} else {
Parameters parameters = provider.getParameters(); // we will need to create this method
NewObject newObject = new NewObject(instantiator, parameters, valuedParameter);
valuedParameter.setValue(newObject.valueWithPropertiesSet());
} What do you think? Did you tried something like that? |
I dislike to add beanutils because have too poor design (static methods that makes unit tests a nightmare), are too slow. And we already have a lib to work with reflection: Mirror. And there is a better way to write this feature using the @lucascs suggestion. |
This closes #940.
@Turini Can you take a look please?
Obs: I had to add the
commons-beanutils
dependency from Apache.@lucascs