
|
If you were logged in you would be able to see more operations.
|
|
|
XStream
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
|
|
|
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}
|
|
Description
|
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} |
Show » |
|