XStream

@XStreamImplicit() for ArrayList<ArrayList<Type>> throws ClassCastException

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.2.2
  • Fix Version/s: 1.3
  • Component/s: Core
  • Labels:
    None
  • JDK version and platform:
    Sun 1.5.0_1 for Windows

Description

...
@XStreamImplicit(itemFieldName="line")
ArrayList<ArrayList<Point>> lines;
...
Annotations.configureAliases(xstream, PolyLine.class); ...

throws

java.lang.ClassCastException:
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
at com.thoughtworks.xstream.annotations.Annotations.getFieldParameterizedType(Annotations.java:226)
at com.thoughtworks.xstream.annotations.Annotations.configureClass(Annotations.java:161)
at com.thoughtworks.xstream.annotations.Annotations.configureAliases(Annotations.java:49)

when configureAliases() is executed.

The old code I used for 1.2.1 still works and is a viable (although ugly) workaround:

xstream.addImplicitCollection(PolyLine.class, "lines", "line", ArrayList.class); // Workaround

Activity

Hide
Guilherme Silveira added a comment -

Commited possible solution which allows ParameterizedTypes to contain other ParameterizedTypes.

Show
Guilherme Silveira added a comment - Commited possible solution which allows ParameterizedTypes to contain other ParameterizedTypes.
Hide
Joerg Schaible added a comment -

Set resolution to fixed, still waiting for Klaus' comment and closing of the issue ...

Show
Joerg Schaible added a comment - Set resolution to fixed, still waiting for Klaus' comment and closing of the issue ...
Hide
Paul van der Maas added a comment -

This fix probably also fixes my issue, but I wanted to let you know anyway, so you can test it.

The problem Klaus is referring to also comes up when you use the @XStreamContainedType annotation on a type where the parameter type is also a parameterized type:

@XStreamContainedType()
public List<List<CarModel>> carModels = new ArrayList<List<CarModel>>();

Here's the exception:

java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
at com.thoughtworks.xstream.annotations.Annotations.configureParameterizedTypes(Annotations.java:249)
at com.thoughtworks.xstream.annotations.Annotations.configureClass(Annotations.java:132)
at com.thoughtworks.xstream.annotations.Annotations.configureAliases(Annotations.java:49)

Also, I was wondering if the fix actually looked at contained types in contained types, or if it is just a superficial fix.
For instance, in my example, if I had an alias defined for CarModel, would the alias be registered or not? I think it should be.

I couldn't get a 'lastest snapshot' from your repository, the links on this page don't work:
http://xstream.codehaus.org/download.html

How do I get a recent snapshot?

Thanks,

Paul

Show
Paul van der Maas added a comment - This fix probably also fixes my issue, but I wanted to let you know anyway, so you can test it. The problem Klaus is referring to also comes up when you use the @XStreamContainedType annotation on a type where the parameter type is also a parameterized type: @XStreamContainedType() public List<List<CarModel>> carModels = new ArrayList<List<CarModel>>(); Here's the exception: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class at com.thoughtworks.xstream.annotations.Annotations.configureParameterizedTypes(Annotations.java:249) at com.thoughtworks.xstream.annotations.Annotations.configureClass(Annotations.java:132) at com.thoughtworks.xstream.annotations.Annotations.configureAliases(Annotations.java:49) Also, I was wondering if the fix actually looked at contained types in contained types, or if it is just a superficial fix. For instance, in my example, if I had an alias defined for CarModel, would the alias be registered or not? I think it should be. I couldn't get a 'lastest snapshot' from your repository, the links on this page don't work: http://xstream.codehaus.org/download.html How do I get a recent snapshot? Thanks, Paul
Hide
Joerg Schaible added a comment -

Closing issues before next release.

Show
Joerg Schaible added a comment - Closing issues before next release.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: