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
Creating WithoutRoot annotation to force JSON deserialization without root. #713
Creating WithoutRoot annotation to force JSON deserialization without root. #713
Conversation
I used the annotation aproach suggested by @lucascs. |
* the License. | ||
*/ | ||
|
||
package br.com.caelum.vraptor; |
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.
Move to serialization's package please
Please add docs at VRaptor's site. |
Add the docs here, in the same PR. it will be merged after 4.1.0.Final release. Ok? |
Ok @Turini. Thanks. |
Done with refactoring. What do you think ? @Turini Today I'll write docs. |
I did a simple text on docs. What do you think ? |
What you think to use Consumes.withoutRoot(true/false) instead a new annotation? |
If I understand you're saying to use Is it ? Sorry if I'm wrong. |
@garcia-jj sorry, but I think that I didn't understand your suggestion. 😒 |
Instead of using a new annotation, add a field into Consumes annotation And change your code to check this new field to use or not root element. |
Adding another field, we'll don't have problem with something like this: |
Nope. Try it.
|
The value passed into |
Yes. You can use like this: @consumes("blah") is equal to @consumes(value="blah")
|
Good idea @garcia-jj. Thanks. What do you think now ? |
~~~ | ||
#!java | ||
@Consumes(value="application/json", withoutRoot=true) | ||
@WithoutRoot |
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.
@WithoutRoot
don't exists anymore.
It's probably ugly, but we could have something like: @Consumes(options=WithoutRoot.class) and options is and: interface DeserializerConfig {
void config(Deserializer deserializer);
} or something like this. Sorry to get at this discussion too late =/ |
This solution supports things like: class NoPassword implements DeserializerConfig {
public void config(Deserializer deserializer) {
deserializer.exclude("password");
}
}
//...
@Consumes(value="application/json", options={WithoutRoot.class, NoPassword.class})
public void update(User user) {...} |
The The |
But it's a good idea. |
The point is to implement this extension ;) |
Any suggestions, @Turini @garcia-jj ? we could use Serializee, or Deserializee, or any other thing like this. |
I really liked the idea. 😃 |
With your help, I can implement this. @lucascs @Turini @garcia-jj 😃 |
I like the idea! It provides much more flexibility when using consumes. @Consumes(value="application/json", options={WithoutRoot.class, NoPassword.class})
public void update(User user) {...} we could do something like this: @Consumes(value="application/json")
@With(options={WithoutRoot.class, NoPassword.class})
public void update(User user) {...} |
what is the advantage of creating another annotation, @Turini ? |
What do you prefer, I try implement it with your help or you do ? |
I know, @Consumes(value="application/json", options={WithoutRoot.class, NoPassword.class,
AnotherElegantOption.class}) I'd prefer my code like this: @Consumes(value="application/json")
@Xpto({WithoutRoot.class, NoPassword.class, AnotherElegantOption.class}) |
It would be only one option most of time, so: @Consumes(value="application/json", options=WithoutRoot.class) is small enough ;) and we could break the line this way: @Consumes(value="application/json",
options={WithoutRoot.class, NoPassword.class,AnotherElegantOption.class}) |
Ok for me, there is no technical reason to create one more annotation anyway ;) Sent from my iPhone
|
About the parameter of |
I think it's better to use something like Serializee: https://github.com/caelum/vraptor4/blob/master/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/Serializee.java |
I agree too.
|
I think I understood. So, does we need to create a class, maybe |
If do you want, I can begin the implementation and growing up the feature with your help. Or do you prefer implement it ? What do you think ? |
If @Consumes(value="application/json", options={WithoutRoot.class, WithRoot.class})
public void update(User user) {...} |
I think that is better close this PR and open a new one. Ok? Sent from my iPhone
|
Ok. Do I begin the other or do you do ? |
Please begin, @renanigt Start with a Deserializee with just |
@lucascs today we doesn't have Thanks for the support. |
When you said that, mean to start |
I mean that you use the existing logic to decide if there is a root or not to set the initial value of |
Oh, now I understand. Thanks a lot. |
Related: #657.
As I said there, I think the best way is to create another annotation, because many user use something like
@Consumes("application/json")
, so if we add another attribute as @jayrmotta said, it doesn't work.What do you think @lucascs @garcia-jj @Turini ?