I been using XStream with great results for a number of tasks, but now I run 
into a problem that seems to boil down to the order in which the XStream object 
is configured.

I've made a simplified example:

<doc>
  <intro>
    <link>
      <url>/foo/bar</url>
    </link>
  </intro>
  <link>
    <url>/up/down</url>
    <image>cat.jpg</image>
  </link>
</doc>

The setup is like:

XStream xstream = new XStream();
xstream.alias("doc", DocText.class);
xstream.addImplicitCollection(DocText.class, "links");
xstream.alias("intro", Paragraph.class);

xstream.alias("link", UrlLink.class); // 1
xstream.alias("link", ImageLink.class); // 2

The gist of the classes:

public class DocText {
        private Paragraph intro;
        private List<ImageLink> links;
}

public class Paragraph {
         UrlLink link;
}

public class UrlLink {
        String url;
}

public class ImageLink {
        private String url;
        private String image;
}

When the sequence of the lines marked 1 & 2 is as shown it works. When they 
change place it throws the following exception:

No such field com.codedroids.oc.schema.dao.UrlLink.image
---- Debugging information ----
field : image
class : com.codedroids.oc.schema.dao.UrlLink
required-type : com.codedroids.oc.schema.dao.UrlLink
converter-type : 
com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /doc/link/image
line number : 9
class[1] : com.codedroids.oc.schema.dao.DocText
version : null
------------------------------- 

If DocText has a simple field called link rather than a list of them, then it 
works either way (after removing the xstream.addImplicitCollection() of 
course). 

The problem is that I am trying to get the xstream configuration generated 
automatically from the related schema definition and thus cannot be sure in 
which order the various alias'es gets invoked.

I haven't tried using annotations since there places where the same class is 
mapped by more than one tag name - this works fine with alias'es but with 
annotation I can only map it to one tag name (or perhaps I'm mistaken)

Thanks
Claus


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

    http://xircles.codehaus.org/manage_email


Reply via email to