XStream

XStream isn't consistent with Annotations.configureAliases method

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.3
  • Component/s: None
  • Labels:
    None
  • JDK version and platform:
    Sun 1.5.0_06 for linux

Description

We've a XML file with one root node (and some other attributes), and 2, 3 level nodes with a process of reading (xstream.fromXML).
a) The third level, before we change the business logic, it was a normal unique attribute. Configured the with Annotations.configureAliases(xstream, RootClassTest.class) was suficiently for the XStream find out all the other annotations in RootClassTest.class, and their HAS-A classes.
Therefore, all attributes from XML were mapped to RootClassTest and their children, by a single Annotations.configureAliases() invocation.

b) We changed the business logic and the 3 level attribute, named "objeto_postal", changed to List of "objeto_postal", thereby,
A implicit Collection was configured in the RootClassTest's child class to understand it as a collection.
The problem is that the system thrown a com.thoughtworks.xstream.mapper.CannotResolveClassException.

I understood that inserting a Annotations.configureAliases for each Annotated class related in XML, the problem is solved, but
some things are wrong, in contract terms:

1) If the configureAliases is needed for the unique RootClass node, all the annotated class, in relation HAS-A and HAS-MANY, should
be annotated automatic, not just HAS-A attributes. The main cause for this misunderstood is that configureAliases' javaDoc doesn't specify
the contract: "All annotated class must be configured". Even more I configured HAS-A classes annotated that ran without to use configureAliases.

2) If the configureAliases is needed for ALL topLevel nodes (when classes is annotated), so the framework doesn't cannot accept HAS-A annotated class not configured with.

If the XStream framework report a correct Exception (class annotated but not configured...No alias or annotation found for the element XXX in XML's reader process), it will be fine.

Activity

Hide
Jonatas Wingeter Rodrigues added a comment -

The version is the latest XStream 1.2.1.

Show
Jonatas Wingeter Rodrigues added a comment - The version is the latest XStream 1.2.1.
Hide
Guilherme Silveira added a comment -

configureClass(type) now works as follows:

1. if the type has already/is currently being visited, skip
2. marks the type as visited
3. configures the type itself
4. for each field
4.1. if @XStreamContainedType is present, recursive call to the fields parameterized types
4.2. configure field level aliases
4.3. recursive call to the field type

The javadoc has been updated accordingly.

Show
Guilherme Silveira added a comment - configureClass(type) now works as follows: 1. if the type has already/is currently being visited, skip 2. marks the type as visited 3. configures the type itself 4. for each field 4.1. if @XStreamContainedType is present, recursive call to the fields parameterized types 4.2. configure field level aliases 4.3. recursive call to the field type The javadoc has been updated accordingly.
Hide
Joerg Schaible added a comment -

The complete code has been refactored and your annotations should be detected now. You may give the head revision a try.

Show
Joerg Schaible added a comment - The complete code has been refactored and your annotations should be detected now. You may give the head revision a try.
Hide
Joerg Schaible added a comment -

Closing issues before next release.

Show
Joerg Schaible added a comment - Closing issues before next release.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: