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

Fix Get Adapters in Proxy Class #995

Merged
merged 3 commits into from
Jul 23, 2015
Merged

Fix Get Adapters in Proxy Class #995

merged 3 commits into from
Jul 23, 2015

Conversation

clairton
Copy link
Contributor

Possible create Serializers without producers, Before throw a expcetion:

java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
    at br.com.caelum.vraptor.serialization.gson.GsonBuilderWrapper.getAdapterType(GsonBuilderWrapper.java:99)
    at br.com.caelum.vraptor.serialization.gson.GsonBuilderWrapper.create(GsonBuilderWrapper.java:74)
    at br.com.caelum.vraptor.serialization.gson.GsonDeserialization.deserialize(GsonDeserialization.java:95)
    at br.com.caelum.vraptor.serialization.gson.GsonDeserialization$Proxy$_$$_WeldClientProxy.deserialize(Unknown Source)
    at br.com.caelum.vraptor.observer.DeserializingObserver.deserializes(DeserializingObserver.java:96)

Type[] genericInterfaces = adapter.getClass().getGenericInterfaces();
ParameterizedType type = (ParameterizedType) genericInterfaces[0];
Type actualType = type.getActualTypeArguments()[0];
final Class<?> klazz;
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using String comparison you should use CDIProxies.isCDIProxy method to check if the class is a proxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I didn't know CDIProxies.isCDIProxy is there.
I write a better test.

@garcia-jj
Copy link
Member

I don't understand if the proxy was created by Hibernate, Javassist, CDI, or another kind of proxy. Can you explain better to us? Thanks for your pr.

@clairton
Copy link
Contributor Author

Sorry about that, is a CDI proxy with Weld.
I did a better test to explain this.

public JsonElement serialize(Bean src, Type typeOfSrc, JsonSerializationContext context) {
return element;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

@clairton this test fails without your changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes @Turini.

final Class<?> klazz = extractRawTypeIfPossible(adapter.getClass());
final Type[] genericInterfaces = klazz.getGenericInterfaces();
final ParameterizedType type = (ParameterizedType) genericInterfaces[0];
final Type actualType = type.getActualTypeArguments()[0];
Copy link
Member

Choose a reason for hiding this comment

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

yeah, much better! ;)
for curiosity, is this an eclipse save action adding final, or a personal habit?
no need for changing this, I'm ok with and without that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a personal habit.
I think it better to understand the code. But I can take off if necessary.
Thank's.

Copy link
Member

Choose a reason for hiding this comment

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

no worries, you can leave it as it is :)

@Turini
Copy link
Member

Turini commented Jul 23, 2015

@lucascs @garcia-jj any downvotes here? if not, I'll include this PR on RC3 release
(i'll launch it as soon as i get an answer)

@garcia-jj
Copy link
Member

Sounds good for me. 🏇 Thanks to fix me about extractRawTypeIfPossible @Turini. Some months without contributing with VRaptor I miss some features.

@Turini
Copy link
Member

Turini commented Jul 23, 2015

thank you @garcia-jj, and welcome back ;)
@clairton thanks for your PR, I'm merging it to be shipped with RC3

Turini added a commit that referenced this pull request Jul 23, 2015
Fix Get Adapters in Proxy Class
@Turini Turini merged commit ba2c627 into caelum:master Jul 23, 2015
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.

None yet

3 participants