I have a working version which solves the inheritance issue by only processing the field alias for the declaring class and the super class is treated as it would be normally.
This is unfortunately wrong.
<nodeB><name>Helloworld</name>Javaworld</nodeB>
This is mixed mode XML which is not supported by XStream. It cannot be read again i.e. a HierarchicalStreamReader will behave in an undefined way. Using a field as text value for a XML element implies that any other field (inherited or not) has to be expressed as attribute.
Apart from this, your solution would not cover case 1 + 3.
As already said, XStream already provides the required functionality with ToAttributedValueConverter. The annotation solution should not behave differently at all.
Ralph, I am a bit in a dilemma with your contribution. I realize that all my comments are negative and not very motivating and I am hating my answers for that. However, they way you have implemented this shows that you really took a deep look into XStream's structures and you understood how XStream works in principle. We'd love to have more of such impressive contributions - it's just a very special case here, therefore don't get me wrong.
Maybe a better way is to modify @XStreamAlias to add an optional field parameter which would be the name of the field that handles the text value; i.e.
@XStreamAlias(value="node", field="text")
{ private String text = "Something Brilliant"; }public class Node
would be serialized as:
<node>Something Brilliant</node>
This would also get around the issues of allowing one field per class, inheritance etc...