Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nykolaslima
Copy link
Contributor

This closes #940.

@Turini Can you take a look please?

Obs: I had to add the commons-beanutils dependency from Apache.

@lucascs

valuedParameter.setValue(value);
} else {
Object mergedValue = objectMerger.merge(existingValue, value);
valuedParameter.setValue(mergedValue);
Copy link
Member

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?

Copy link
Contributor Author

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?

@lucascs
Copy link
Member

lucascs commented Mar 4, 2015

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?

@nykolaslima
Copy link
Contributor Author

@lucascs We could try to do this with IOGI but we would need to guarantee the order of the observers. It depends on executing DeserializingObserver first.

With the current CDI version we can't guarantee it. Maybe when CDI 2.0 is released we can change it and remove the commons-beanutils dependency.

@Turini Turini added this to the 4.2.0.Final milestone Mar 5, 2015
@Turini
Copy link
Member

Turini commented Mar 5, 2015

It'd be great do not depend on the order of observers like this PR proposes.
@lucascs can you think in a way to do that without adding this dependency?
If it's possible, it would be even better (I couldn't look deep into this code yet)

@lucascs
Copy link
Member

lucascs commented Mar 6, 2015

If you use this class from IOGI:
https://github.com/rafaeldff/Iogi/blob/master/src/br/com/caelum/iogi/reflection/NewObject.java

construct it with VRaptorInstantiator, the request parameters and the deserialized object, you just use valueWithPropertiesSet

Something like this should work.

@nykolaslima
Copy link
Contributor Author

Actually I didn't understand. Do you have any example of this being used?

@lucascs
Copy link
Member

lucascs commented Mar 8, 2015

@nykolaslima
Copy link
Contributor Author

@lucascs but this NewObject will copy all object levels?

Remembering that not only the first level should be handled.

e.g.

public class A {
  private B b;
}

public class B {
  private C c;
}

We could use in our controller:

@Post("/xpto/{a.b.c}")
public void something(A a) {
}

@lucascs
Copy link
Member

lucascs commented Mar 9, 2015

Not sure, try it please =)

@nykolaslima
Copy link
Contributor Author

Ok!

I'll give it a try and after it I'll give a feedback here!

Thank you!

@nykolaslima
Copy link
Contributor Author

Guys, I could not make this work with NewObject. Couldn't we merge it with Apache lib?

@Turini
Copy link
Member

Turini commented Mar 31, 2015

@nykolaslima sorry my delay. Before doing that I'll give a try to NewObject.

I'll be back with the result soon :)

@nykolaslima
Copy link
Contributor Author

No problem. I'll wait for your response. Thank you!
On Tue, Mar 31, 2015 at 4:26 AM Rodrigo Turini [email protected]
wrote:

@nykolaslima https://github.com/nykolaslima sorry my delay. Before
doing that I'll give a try to NewObject.

I'll be back with the result soon :)


Reply to this email directly or view it on GitHub
#953 (comment).

@Turini
Copy link
Member

Turini commented Mar 31, 2015

@nykolaslima, You'll need to inject VRaptorInstantiator to provide it to the NewObject and create a new method on ParametersProvider that returns the br.com.caelum.iogi.parameters.Parameters (it already has a private method to do that). Your if will look like this:

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?

@garcia-jj
Copy link
Member

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.

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

Successfully merging this pull request may close these issues.

Deserialize JSON with path param
4 participants