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

Key: XSTR-450
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Joerg Schaible
Reporter: Dimitar Dimitrov
Votes: 0
Watchers: 1
Operations

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

Mixing annotation and API calls for aliasing and use-attribute does not work

Created: 19/Nov/07 12:28 AM   Updated: 25/Feb/08 05:02 PM
Component/s: Annotations
Affects Version/s: 1.2.2
Fix Version/s: 1.3


 Description  « Hide
If we alias a field name using @XStreamAlias annotation and setup the field's type to be converted to attribute, using XStream.useAttributeFor(), the alias annotation gets ignored.

If we define both the alias and the "as field" using API cals or both of them using annotations - everything works as expected.

{code}
class Foo {
    static String ACTUAL = "<Foo camelCase='5' dash-separated='10'/>";
    static String DESIRED = "<Foo camel-case='5' dash-separated='10'/>";

    @XStreamAlias ("camel-case")
    int camelCase = 5;

    @XStreamAsAttribute
    @XStreamAlias("dash-separated")
    int dashSeparated = 10;

    public static void main(String[] args) {
        XStream xs = new XStream();
        xs.useAttributeFor(int.class);
        Annotations.configureAliases(xs, Foo.class);
        assert xs.toXML(new Foo()).replace("\"", "'").equals(ACTUAL);
        assert xs.toXML(new Foo()).replace("\"", "'").equals(DESIRED);
    }
}
{code}

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Joerg Schaible - 23/Nov/07 04:07 PM
Solved in the head revision. You may give it a try.

Joerg Schaible - 25/Feb/08 05:02 PM
Closing issues before next release.