History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-365
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Assignee: Unassigned
Reporter: Lucio Benfante
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
XStream

Multiple implicit collections with @XStreamImplicitCollection annotation

Created: 27/Nov/06 09:27 AM   Updated: 24/May/07 12:38 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2.2

File Attachments: 1. File annotations.diff (1 kb)
2. Java Source File Annotations.java (9 kb)
3. Java Source File Annotations.java (8 kb)
4. File implicit_collections.diff (3 kb)
5. Java Source File ImplicitCollectionTest.java (2 kb)
6. Java Source File XStreamImplicit.java (0.6 kb)
7. Java Source File XStreamImplicitCollection.java (0.4 kb)


JDK version and platform: 1.5


 Description  « Hide
Hello,
I was trying to map an XML file with multiple collections that must mapped as implicit collections.

I would like to map them using Java 5 annotations, but at the class level I can use a single @XStreamImplicitCollection having a single String parameter for the collection. Don't know if I missed something, or if I'm using the wrong approach. Please let me know if I'm in the latter case.

At present, for having things working, I modified XStreamImplicitCollection.java and Annotation.java sources for having an array of parameters. So I can map multiple collection writing the following code:

@XStreamAlias("Widget")
@XStreamImplicitCollection({"properties", "containers"})
public class Widget {
private String Name;
private List<Property> properties = new ArrayList<Property>();
private List<Container> containers = new ArrayList<Container>();
}

I attached the modified sources and the diff file. Hope this can help.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Joerg Schaible - 27/Nov/06 06:25 PM
Hi Lucio,

the problem with this modification is, that it breaks backward compatibility. Nevertheless, we were discussing internally about this annotation anyway, since we have the impression, it should be assigned to a field and not to a class.

... we'll see ...

Lucio Benfante - 27/Nov/06 11:06 PM
Hi Joerg,
yes, I know it's breaking compatibility. It was just an hack for pressure.

An field annotation could be a better solution. Have you an estimate of when that feature could be availble in XStream? Let me know if I could help.

Lucio

Lucio Benfante - 28/Nov/06 06:36 AM
Hi,
I just relized that my patch is in fact backward compatible.

If you have a single implicit collection in you class, you can still write:

@XStreamImplicitCollection("properties")...

Of course a field annotation could still be better...

Lucio

Joerg Schaible - 28/Nov/06 04:13 PM
Hehehe, you simply revealed my lack of JDK 5 knowledge :)

Lucio Benfante - 01/Dec/06 10:05 AM
Hello,
as discussed in the dev mailing-list, a field annotation is a better approach for defining an implicit collection.

I implemented it for my purposes. Attached you'll find:

* XStreamImplicit.java : source of the new field level annotation

* ImplicitCollectionTest.java : some tests of the new annotation

* Annotations.java : modified source of the annotation configurator

* annotations.diff : diff file between the original Annotations.java and my modifed file.

Hope this help, and could be integrated in XStream.

Lucio

Lucio Benfante - 01/Dec/06 10:08 AM
Implementation and tests of the @XStreamImplicit field annotation.

Lucio Benfante - 01/Dec/06 10:09 AM
Diff file of Annotations.java after the introduction of the @XStreamImplicit field annotation

Joerg Schaible - 01/Dec/06 03:16 PM
Hi Lucio,

thanks a lot for the patch and the test cases. I've applied it to the subversion repository. You might build a SNAPSHOT version of XStream yourself.

- Jörg