I managed to create three almost identical converters for the three ArrayList<String> elements of my Java structure and I can both read and write XML in the desired format.

I was unable to see how to get the CollectionConverter or NamedCollectionConverter to fit in. I don't have distinct types for the three lists and the examples I saw assumed a distinct type for the collection.

I was trying to use the annotation approach because that seemed to be the only way to be specific about which of the ArrayLists I was referring to. It was not clear how to proceed and trial and error was not effective for me.

What I would really like is an annotation or combination of annotations that combines a top level alias with an implicit alias, something like

  @XStreamCollection("movies", "title")
  ArrayList<String> movies;

  @XStreamCollection("plays", "title")
  ArrayList<String> plays;

etc., producing
  ...
  <movies>
    <title>Title 1</title>
    <title>Title 2</title>
  </movies>
  <plays>
    <title>Title 1</title>
    <title>Title 2</title>
  </plays>

It seems to me that simple collections or maps are somewhat special. If it were more complex than a simple collection, a person would typically want to develop a class but for just a list of items a special class is much less compelling.


On 2/24/14 5:03 PM, Jörg Schaible wrote:
Hi Paul,

Paul B. Anderson wrote:

I'm still struggling.  Where can I find ParameterizedConverterTest?
https://fisheye.codehaus.org/browse/xstream/trunk/xstream/src/test/com/thoughtworks/acceptance/annotations/ParametrizedConverterTest.java?r=2131

One additional aspect:  I have three instances of the ArrayList<String>
in my object, each with different inner element names.
Register a local converter for each instance.

Also have a look at the parallel thread with the CollectionConverter and
@XStreamConverter annotation.

Cheers,
Jörg


On 2/24/14 1:46 PM, Jörg Schaible wrote:
Hi Paul,

Paul B. Anderson wrote:

I'm trying to handle an ArrayList<String> to achieve XML like the
following:

      <entries>
        <entry>Alpha</entry>
        <entry>Bravo</entry>
        <entry>Charlie</entry>
      </entries>

The examples Ive seen let me name the outer <entries> element or
eliminate the outer element and name the inner elements. Is there a way
to
achieve both?  I'm using annotations but I'm not tied to them.
Register a local converter of type NamedCollectionConverter for the
field. This is also possible with annotations, but a bit tedious. You may
have a look at the ParameterizedConverterTest for an example.

Cheers,
Jörg


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

      http://xircles.codehaus.org/manage_email




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

     http://xircles.codehaus.org/manage_email


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

     http://xircles.codehaus.org/manage_email





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

   http://xircles.codehaus.org/manage_email


Reply via email to