If I change this line
Then it works as expected.
How can dynamically assign alias by object class type?
posted 2 years ago
Due to XStream's use of its registry of Converters, you've sometime need to know exactly how it behaves, namely, what class to put as the 2nd arugment in the alias method. This, I think, is arguably troublesome...
In order to make serialization always responsive to an object's getClass()'s response as the proper 2nd argument to the alias method, the idea-conductor is to subclass the ClassAliasingMapper. It can be condensed into the set up of the instantiation of the XStream (as shown) and this is how. (I call the subclass SelfDoc... for the responsiveness to .getClass() always, hence, do not need a priori accepting the behaviour of default converters... you may sure call it anything you like.)
You might have to change this to that according to the exact outcome your like better (such as getSimpleName() here, to getName() or getCanonicalName() etc etc..., choose what you feel more comfortable.)