title: How to alias java.lang.Integer using XStream?
body: <p>I'm tweaking an XStream output, and I get the following:</p>
  
  <pre><code>      &lt;entry&gt;
          &lt;string&gt;ahh&lt;/string&gt;
          &lt;java-class&gt;java.lang.Integer&lt;/java-class&gt;
        &lt;/entry&gt;
  </code></pre>
  
  <p>So I try to create an alias for java.lang.Integer.class... Doesn't work. I made aliases for many other classes and it works just fine. I also tried to alias <code>int.class</code>; no luck.</p>
  
  <p>What's the trick?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I realized this question was not clear enough. What I'm interested in is <em>not</em> to alias the element name (XStream does it already very well). I want to alias the data contained in the element. There's nothing like an example:</p>
  
  <p>Here is a test I made:</p>
  
  <pre><code>import java.util.ArrayList;
  
  import com.thoughtworks.xstream.XStream;
  
  public class Main {
  
      public static void main(String[] args) {
          ArrayList&lt;Class&lt;?&gt;&gt; classes = new ArrayList&lt;Class&lt;?&gt;&gt;();
          classes.add(Integer.class);
          classes.add(Long.class);
          classes.add(Double.class);
          classes.add(Float.class);
  
          ArrayList&lt;Number&gt; numbers = new ArrayList&lt;Number&gt;();
          numbers.add(new Integer(3));
          numbers.add(new Long(3));
          numbers.add(new Double(3));
          numbers.add(new Float(3));
  
          XStream xml = new XStream();
          xml.alias("inty", Integer.class);
          xml.aliasType("inty", Integer.class);
          xml.aliasPackage("jl", "java.lang");
  
          System.out.println(xml.toXML(classes));
          System.out.println(xml.toXML(numbers));
      }
  
  }
  </code></pre>
  
  <p>Which outputs:</p>
  
  <pre><code>&lt;list&gt;
    &lt;java-class&gt;java.lang.Integer&lt;/java-class&gt;
    &lt;java-class&gt;java.lang.Long&lt;/java-class&gt;
    &lt;java-class&gt;java.lang.Double&lt;/java-class&gt;
    &lt;java-class&gt;java.lang.Float&lt;/java-class&gt;
  &lt;/list&gt;
  &lt;list&gt;
    &lt;int&gt;3&lt;/int&gt;
    &lt;long&gt;3&lt;/long&gt;
    &lt;double&gt;3.0&lt;/double&gt;
    &lt;float&gt;3.0&lt;/float&gt;
  &lt;/list&gt;
  </code></pre>
  
  <p>As you can see, element names are well aliased (second list), but if I use it as data, I can't find a way to shorten the class names. I tried most of relevant XStream.alias* methods. What I would like is something like (for the first list):</p>
  
  <pre><code>&lt;list&gt;
    &lt;java-class&gt;int&lt;/java-class&gt;
    &lt;java-class&gt;long&lt;/java-class&gt;
    &lt;java-class&gt;double&lt;/java-class&gt;
    &lt;java-class&gt;float&lt;/java-class&gt;
  &lt;/list&gt;
  </code></pre>
  
  <p>Honestly, right now, I doubt this is possible without quite a big hack, but I'm at least sharing the idea.</p>