-
Notifications
You must be signed in to change notification settings - Fork 204
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
making VRaptorGsonBuilder a component #561
making VRaptorGsonBuilder a component #561
Conversation
…rojects that uses VRaptor.
public VraptorGsonBuilder getInstance() { | ||
ExclusionStrategy exclusion = new Exclusions(serializee); | ||
|
||
return new VraptorGsonBuilder(serializers.getSerializers(), Arrays.asList(exclusion)); |
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 is this a component factory? Why not make VRaptorGsonBuilder a @PrototypeScoped @Component
?
Also, please rename VraptorGsonBuilder
=> VRaptorGsonBuilder
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.
Can we inject a List directly in VRaptorGsonBuilder? How can we create a ExclusionStrategy
using the serializee
to use in VRaptorGsonBuilder
without a component factory?
We can make it @PrototypeScoped
like you said.
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.
you can put this creation logic inside VRaptorGsonBuilder
@lucascs take a look now =) If you merge it, can you generate a SNAPSHOT for me? |
new DefaultJsonSerializers(Collections.<JsonSerializer> emptyList())); | ||
serializee = new Serializee(); | ||
|
||
VRaptorGsonBuilder builder = new VRaptorGsonBuilder(new DefaultJsonSerializers(Collections.<JsonSerializer> emptyList()), serializee); |
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.
you can use createBuilder
here
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.
you still can use createBuilder()
;)
This is cool! Currently I have make a workaround 😞 like this to get an instance of Gson: |
Hey @lucascs, take a look now |
@@ -17,7 +20,8 @@ | |||
*/ | |||
|
|||
@SuppressWarnings("rawtypes") | |||
public class VraptorGsonBuilder { |
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.
It's missing an @Component
here.
Sorry, I missed |
|
||
GsonJSONSerialization serialization = new GsonJSONSerialization(response, extractor, initializer, new DefaultJsonSerializers(adapters)); | ||
|
||
GsonJSONSerialization serialization = new GsonJSONSerialization(response, extractor, initializer, createBuilder(new CollectionSerializer()), serializee); |
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.
I'd extract another method here:
JSONSerialization serialization = serializationWithAdapter(new CollectionSerializer());
//...
public JSONSerialization serializationWithAdapter(JsonSerializer adapter) {
return new GsonJSONSerialization(response, extractor, initializer, createBuilder(adapter), serializee);
}
So we can better express the test intent.
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.
Yes Lucas, I agree with you. I changed it and tests look better. Can you take a look now?
…onent making VRaptorGsonBuilder a component
Thanks! |
Can you generate a SNAPSHOT with this, please? |
Thank you! |
@nykolaslima something went wrong here. If I do this:
The class Endereco not longer being serialized =/ |
Any exception or something? |
Nothing.. |
@dipold I have made a test with this situation that you exposes but here the serialization works fine. Are you using Gson serialization? |
We have tests for this... maybe the problem is that |
I created a new project to be sure about the problem. And the problem persists. What I found in debug mode, at the moment, is that And that does not happen in units tests. I tried to create a unit test without success. My project configuration:
controller:
|
Try again please with this snapshot: |
Thanks @lucascs |
I think there's one more thing to fix. |
What is the result of this? |
But estado and microRegiao are proxies... I think that is why it is throwing the exception... can't you delegate the serialization instead of calling |
You are right! How I can delegate? I tried change the code to bellow and now works fine:
I think we can do it, given that ctx never invoke on the src object itself since that will cause an infinite loop. |
Change this and send a Pull request please =) |
We can use
VRaptorGsonBuilder
to make serialization in "VRaptor way".e.g.:
vRaptorGsonBuilder.create().toJson(representation);
In order to use
VRaptorGsonBuilder
in other projects, we need to make it a component to be injected through DI container.With this changes we are also improving code quality, by receiving
VRaptorGsonBuilder
as a dependency, removing the responsability ofGsonJSONSerialization
of build it.