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

Fixing instability with deserializing and instantiator order #680

Merged
merged 6 commits into from
Jul 12, 2014

Conversation

Turini
Copy link
Member

@Turini Turini commented Jul 10, 2014

Closes #668

@Turini Turini self-assigned this Jul 10, 2014
@Turini Turini added the bug label Jul 10, 2014
@garcia-jj
Copy link
Member

I dislike this inline if. What you think if you extract to method names hasConstraint and add this check in existent if?

@Turini
Copy link
Member Author

Turini commented Jul 10, 2014

done, what about now?

@garcia-jj
Copy link
Member

Turini, I really sorry about my typo (my cellphone is too bad). I think in something like:

if (isNotParameterless() && hasNoConsumes())

That means, only extract your method.containsAnnotation(Consumes.class) to a method.

But since you already merged both methods, may we can rename to another name (hasConstraint is a mistake, because we don't have any constraint here).

Suggestions? I'm not good with names. My two dogs know about this :)

@Turini
Copy link
Member Author

Turini commented Jul 10, 2014

no worries, I'll change it tomorrow =)

return methodInfo.getControllerMethod().getArity() > 0;
public boolean hasConstraint() {
ControllerMethod method = methodInfo.getControllerMethod();
return method.getArity() < 0 || method.containsAnnotation(Consumes.class);
Copy link
Member

Choose a reason for hiding this comment

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

arity will never be less than 0 ;)

use == 0

@lucascs
Copy link
Member

lucascs commented Jul 11, 2014

My only concern about this PR is that we won't support:

@Post("/product/{product.id}")
@Consumes
public void update(Product product) {....}

or

@Post("/product/{product.id}/reviews")
@Consumes
public void add(Review review, Product product) {....}

@rponte
Copy link
Contributor

rponte commented Jul 11, 2014

Not supporting this kind of parameters within url is not a good thing :-T

On Thu, Jul 10, 2014 at 11:24 PM, Lucas Cavalcanti <notifications@github.com

wrote:

My only concern about this PR is that we won't support:

@post("/product/{product.id}")@Consumespublic void update(Product product) {....}

or

@post("/product/{product.id}/reviews")@Consumespublic void add(Review review, Product product) {....}


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

Rafael Ponte
TriadWorks | Formação Java
http://cursos.triadworks.com.br

@Turini
Copy link
Member Author

Turini commented Jul 11, 2014

yes, this is not nice... I'll write some tests and change the code to cover that

@Turini
Copy link
Member Author

Turini commented Jul 11, 2014

this example provided for @lucascs does not work independent of
observers order or using events or interceptors... and I guess neither in
vr3 it works :) but I'm trying a solution for it anyway... this is important.

@defaultbr
Copy link
Contributor

its different from VRaptor 3? i've never used @consumes in VRAptor 3, but i heard that it work perfectly using VRaptor 3, so maybe can use the same idea? or cant because the CDI?

@Turini
Copy link
Member Author

Turini commented Jul 11, 2014

Done! Now the code works fine independent of execution
order and works with path parameters, just like:

@Consumes("application/json")
@Path("/url/{id}")
public void test(Long id, Curso curso) {
    System.out.println("ID "+id);
    System.out.println("JSON "+ curso);
    result.forwardTo(this).index();
}

Or even:

@Consumes("application/json")
@Path("/url/{curso.id}/{curso.nome}")
public void test2(Curso curso, Curso curso2) {
    System.out.println("URL "+curso);
    System.out.println("JSON "+ curso2);
    result.forwardTo(this).index();
}

@Turini
Copy link
Member Author

Turini commented Jul 11, 2014

ẁhat do you think?

} else {
valuedParameters[i].setValue(values[i]);

if (!hasInstantiatableParameters()) return;
Copy link
Member

Choose a reason for hiding this comment

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

good name

@garcia-jj
Copy link
Member

sounds ⛵ to me

@lucascs
Copy link
Member

lucascs commented Jul 12, 2014

🚢, but it doesn't support:

POST /cursos/1234
{"curso": {"nome": "FJ-21"}}
@Post("/cursos/{curso.id}") @Consumes
public void atualiza(Curso curso) {...}

@lucascs
Copy link
Member

lucascs commented Jul 12, 2014

But this is another PR.

Turini added a commit that referenced this pull request Jul 12, 2014
Fixing instability with deserializing and instantiator order
@Turini Turini merged commit eee4911 into master Jul 12, 2014
@Turini Turini deleted the deserilizingBug branch July 12, 2014 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

instability in consumes feature
5 participants