XStream
  1. XStream
  2. XSTR-450

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

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major 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); 
          }
      }
      

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          Dimitar Dimitrov
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: