newbie newbie - 2 months ago 6x
Java Question

XStream changing general alias convention

Now XStream uses class.getName() for aliases, but I would like to use class.getSimpleName(). Is it possible to easily config this, or do I have to manually configure all classes to use simpleName?


The thing is, that your mapping should work both ways, so you can find the class based on the simple name. Since this is not trivial, you should do something yourself. I can see basically two ways to do this.

1. Register aliases

Since you already know what classes you'll be using (since, if you don't, you wouldn't be able to find the class that goes with a simple name), you could register aliases for all classes with something like


2. Create a custom mapper

If you don't feel like registering the aliases for some reason, you can wrap the mapper in a mapper of your own (see for instance the AbstractXmlFriendlyMapper for a basis of this), but still, you will need some way to find out which class belongs to which short name.