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

Deserializing a generic list #23

Open
lsarni opened this issue Feb 21, 2017 · 1 comment
Open

Deserializing a generic list #23

lsarni opened this issue Feb 21, 2017 · 1 comment

Comments

@lsarni
Copy link

lsarni commented Feb 21, 2017

I'm trying to deserialize this

<Collection>
   <item>test uno</item>
   <item>test dos</item>
</Collection>

Using this


@Root(name="Collection")
public class SimpleCollection<T> extends Vector<T> implements Serializable {

        @ElementList(entry="item",inline=true)
       SimpleCollection<T> list = this;
}

The problem is that T is always an Object instead of being of the type that it was initialized (in this case a String).
I tried using an Visitor, and on the read method field is of type Object. Is there a way I can change that?
I now the class of my collection, how can I pass it to the read method?

If I change it like this it works (for strings), but I need it to be generic.

@Root(name="Collection")
public class SimpleCollection<T> extends Vector<T> implements Serializable {

        @ElementList(entry="item",inline=true)
       SimpleCollection<String> list = ( SimpleCollection<String>)this;
}
@Ayutac
Copy link

Ayutac commented Feb 21, 2017

As a workaround, maybe you could create an Interface SimpleXmlSerializable annotated with @root and let T extends this interface. It's just an idea. I think the main problem is the serialization of classes. If you have no problem working with a ClassLoader, you could also serialize T itself by providing an abstract getClass method or a Lambda Class Supplier.

Disclaimer: I'm just a user of SimpleXML

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

No branches or pull requests

2 participants