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 ClassCastException for ParameterizedType #171

Merged
merged 3 commits into from
Oct 8, 2013
Merged

Conversation

dipold
Copy link
Member

@dipold dipold commented Oct 4, 2013

Fix ClassCastException for ParameterizedType as discussed here:
https://groups.google.com/forum/ #! topic/caelum-vraptor4/HQOwfMuLbCY

if (actualType instanceof ParameterizedType)
return (Class<?>) ((ParameterizedType) actualType).getRawType();
else
return (Class<?>) actualType;
}
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

Copy link
Member

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)

Copy link
Member Author

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<?>

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

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?

Copy link
Member

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
.

@dipold
Copy link
Member Author

dipold commented Oct 4, 2013

How I can improve this test? @garcia-jj any suggestion?

I should do the same with JsonDeserializer<> in GsonDeserialization?

@garcia-jj
Copy link
Member

@dipold, this pull request is cleared to :takeoff:?

@dipold
Copy link
Member Author

dipold commented Oct 8, 2013

@garcia-jj As I said in another topic, everything sounds good here

@garcia-jj
Copy link
Member

Oh, sorry. i've missed something. You can ship if you want. Lucas already did your approval.

@dipold
Copy link
Member Author

dipold commented Oct 8, 2013

In fact I am still waiting because I haven´t received feedback...

@garcia-jj
Copy link
Member

:shipit:

dipold added a commit that referenced this pull request Oct 8, 2013
Fix ClassCastException for ParameterizedType and Added the capability to deserialize arrays
@dipold dipold merged commit 425e740 into master Oct 8, 2013
@dipold dipold deleted the fixClassCastException branch October 8, 2013 20:47
@Turini Turini added this to the 4.0.0-beta-2 milestone Mar 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants