Hi Graham, Graham Allan wrote:
> Hi all, > > Hopefully this hasn't been covered before, the closest reference I can > find to this area is an unrelated JIRA bug[1]. > > We are currently using @XStreamImplicit for fields which are Collection > types, which seems to only work with arrays, java.util.Map, and > java.util.Collection. However, with heavy use of the Guava library we > often find ourselves with a field of java.lang.Iterable<X>. We have an > easy workaround of just creating a new collection type, e.g. ArrayList > from the iterable, but it seems a shame to have to create a copy rather > than take advantage of the laziness available with Guava's Iterables. > > Are there any plans to enhance @XStreamImplicit to also accept fields of > type Iterable? In short: No. In long: It cannot. XStream provides only specialized converters for known concrete collection types, since these converters will ignore any additional member field of the collection type and therefore it cannot recreate an equal instance properly anymore. Example: The CollectionConverter of XStream cannot handle properly a TreeSet, because it has no idea that it should also marshal a possible Comparator instance. At deserialization time it would probably create a TreeSet instance, but only without comparator and the deserialized instance will behave and work differently. Therefore XStream delivers explicitly a TreeSetConverter and that's also the reason why e.g. a derived class of ArrayList is handled by the reflection-based SerializableConverter and not by the CollectionConverter. So, you might say, that your collections do not have additional members. Then you're free to register an own Collection converter that overloads the canConvert method and returns true for every type that is assignable to Collection. The situation for Iterable is similar, but you will also have to overload the marshal/unmarshal methods to read/write the class attribute for the concrete type and to initiate the loop. > Thanks for your hard work in creating this library, much appreciated. You're welcome. > Kind regards, > Graham > > > [1] http://jira.codehaus.org/browse/XSTR-606 BTW: I don't have any idea, where the code for this IterableConverter is coming from. Cheers, Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
