Discussion:
[xstream-user] Help unmarshalling Collection/TreeSet
Felipe
2015-04-01 14:42:39 UTC
Permalink
Good morning everyone,

I need help on something:

I'm trying to unmarshall from a huge XML into ValueObjects, but I keep
getting erros, and I'm trying like crazy to make this work, but it has been
a little hard. I've been using XStream for years and it always worked fine,
but now I'm getting slapped in the face.

This huge ValueObject contains lots of primitive and complex types inside
it, and it's complex types contains Collections of TreeSet's.

I've been managed to marshall and unmarshall Collections of ArrayLists well,
but now with this Collections of TreeSets I just can't make it work.

Errors I've been getting:

java.lang.InstantiationError: java.util.Collection

Things I've tried:
xStream.addDefaultImplementation(Collection.class,
MyTypeThatContainsTheCollection);
xStream.addImplicitCollection(MyTypeThatContainsTheCollection, fieldName);
xStream.alias("collectionFieldName", ArrayList.class);

Whats is the thing about XStream and Collections of TreeSet?
I'm afraid I can't explain well where my problem is, but I do not know
anymore. I've been trying this work for more than one week, without success.
What should I know about XStream and Collection/TreeSet. Why I can make it
work well with Collection of ArrayList?
I've been researching google exaustively, and I alaways see examples of
converters, but I just can't figure it out. Should this be the solution for
my problem? Should I implement a converter?


Atenciosamente,
Luiz Felipe


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Jörg Schaible
2015-04-01 19:58:17 UTC
Permalink
Hi Luiz,
Post by Felipe
Good morning everyone,
I'm trying to unmarshall from a huge XML into ValueObjects, but I keep
getting erros, and I'm trying like crazy to make this work, but it has
been a little hard. I've been using XStream for years and it always worked
fine, but now I'm getting slapped in the face.
This huge ValueObject contains lots of primitive and complex types inside
it, and it's complex types contains Collections of TreeSet's.
I've been managed to marshall and unmarshall Collections of ArrayLists
well, but now with this Collections of TreeSets I just can't make it work.
java.lang.InstantiationError: java.util.Collection
xStream.addDefaultImplementation(Collection.class,
MyTypeThatContainsTheCollection);
This does not make sense. Here you've told XStream that it should use a
MyTypeThatContainsTheCollection anywhere it would normally look out for a
Collection. Somehow I doubt that MyTypeThatContainsTheCollection *is* a
Collection at all.
Post by Felipe
xStream.addImplicitCollection(MyTypeThatContainsTheCollection, fieldName);
Here you have told XStream that the Collection stored in "fieldName" is
implicit i.e. all its elements are siblings to any other field of
MyTypeThatContainsTheCollection.
Post by Felipe
xStream.alias("collectionFieldName", ArrayList.class);
You have told XStream now, that it should use the name "collectionFieldName"
for the type name ArrayList. However, since ArrayList is the default
implementation of a List and a list's alias is "list", the alias for
ArrayList is hardly used at all.
Post by Felipe
Whats is the thing about XStream and Collections of TreeSet?
I'm afraid I can't explain well where my problem is, but I do not know
anymore. I've been trying this work for more than one week, without
success. What should I know about XStream and Collection/TreeSet. Why I
can make it work well with Collection of ArrayList?
It depends on the declaration of the field "fieldName" in
MyTypeThatContainsTheCollection. The default implementation of that
declaration determines the real type of the deserialized collection.
Post by Felipe
I've been researching google exaustively, and I alaways see examples of
converters, but I just can't figure it out. Should this be the solution
for my problem? Should I implement a converter?
Well, without knowing your real Java declarations nor the XML, I cannot say
a lot more. Did you at least use the XStream to serialize your object model?
Only if that XML output matches the format of the XML you want to read, you
have at least a chance. Setting up an XStream solely by looking at the input
is very, very, error-prone any annoying, as you have already learned. Do it
always the other way round.

Cheers,
Jörg



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...