-
Notifications
You must be signed in to change notification settings - Fork 332
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 ClassCastException for ParameterizedType #171
Conversation
if (actualType instanceof ParameterizedType) | ||
return (Class<?>) ((ParameterizedType) actualType).getRawType(); | ||
else | ||
return (Class<?>) actualType; | ||
} |
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 you write a test for this case?
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.
Sure
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 not change getActualType
to return Type
? (Class<?> implements Type)
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.
because registerTypeHierarchyAdapter
is expecting a Class<?>
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 it: http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/GsonBuilder.html#registerTypeAdapter(java.lang.reflect.Type, java.lang.Object)
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 just tested your suggestion here and unfortunately doesn´t work as expected.
When I register a JsonSerializer<Enum<?>>
the behavior expected is that all enums has intercept by this serializer, but none is intercepted.
Using registerTypeAdapter()
Gson probably expect the type to be intercepted is exactly equals to Enum<?>
Any other suggestion?
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.
No, 🚢
On Fri, Oct 4, 2013 at 11:56 AM, Rafael Dipold notifications@gitpro.ttaallkk.topwrote:
In
vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/gson/VRaptorGsonBuilder.java:@@ -85,8 +85,11 @@ public Gson create() {
Type[] genericInterfaces = adapter.getClass().getGenericInterfaces();
ParameterizedType type = (ParameterizedType) genericInterfaces[0];Type actualType = type.getActualTypeArguments()[0];
return (Class<?>) actualType;
if (actualType instanceof ParameterizedType)
return (Class<?>) ((ParameterizedType) actualType).getRawType();
else
}return (Class<?>) actualType;
I just tested your suggestion here and unfortunately doesn´t work as
expected.When I register a JsonSerializer<Enum<?>> the behavior expected is that
all enums has intercept by this serializer, but none is intercepted.Using registerTypeAdapter() Gson probably expect the type to be
intercepted is exactly equals to Enum<?>Any other suggestion?
—
Reply to this email directly or view it on GitHubhttps://github.com//pull/171/files#r6769781
.
How I can improve this test? @garcia-jj any suggestion? I should do the same with |
@dipold, this pull request is cleared to :takeoff:? |
@garcia-jj As I said in another topic, everything sounds good here |
Oh, sorry. i've missed something. You can ship if you want. Lucas already did your approval. |
In fact I am still waiting because I haven´t received feedback... |
Fix ClassCastException for ParameterizedType and Added the capability to deserialize arrays
Fix ClassCastException for ParameterizedType as discussed here:
https://groups.google.com/forum/ #! topic/caelum-vraptor4/HQOwfMuLbCY