Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 1.2.2
-
Fix Version/s: 1.3
-
Component/s: Annotations
-
Labels:None
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.
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); } }
Solved in the head revision. You may give it a try.