History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-55
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Joe Walnes
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
XStream

Ability to alias an entire package

Created: 06/May/04 02:20 PM   Updated: 02/Nov/05 06:38 PM
Component/s: Core
Affects Version/s: 1.1
Fix Version/s: Upcoming

File Attachments: 1. Java Source File ClassAliasingMapperTest.java (4 kb)
2. Text File package.patch (3 kb)
3. Zip Archive xstream-package-alias-patch.zip (7 kb)



 Description  « Hide
Rather than having to do:

xstream.alias("com.blah.mypackage.MyClass", "MyClass");
xstream.alias("com.blah.mypackage.YourClass", "YourClass");
xstream.alias("com.blah.mypackage.SheepClass", "SheepClass");

I'd like to be able to do:

xstream.aliasPackage("com.blah.mypackage");



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Grégory Joseph (old account) - 18/Jul/04 10:31 AM
Here's a very basic patch that allows this.
I've factored out two methods in DefaultClassMapper and made the loadClass method of DefaultClassMapper protected; this PackageAliasClassMapper simply extends DefaultClassMapper.
Please review and tell me what you think.

Grégory Joseph (old account) - 20/Jul/04 03:05 PM
The previous patch isn't really satisfying me, because :
  • it doesn't actually map a package name to a "shortcut" name, but to empty string (ie, com.blah.bleh.SomeClass can not be aliased to "foo.SomeClass" but only to SomeClass)
  • it's based on startsWith and substring methods, which makes it a bit hairy - and possibly not very safe - for the sake of aliasing com.blah.bleh.bluh.SomeOtherClass to "bluh.SomeOtherClass"

I'm planning on submitting another patch that would

  • allow actual aliasing of a package to a "prefix", but only A package and not it's subpackages
  • be based on full package name of a Class instead of just using startsWith on Class.getName()

... I'll do that .. eventually.. when my pc resurects.

Please tell me what you think, anyway


Maarten Winkels - 02/Nov/05 06:27 PM
Some basic tests that demonstrate this behaviour.

Maarten Winkels - 02/Nov/05 06:38 PM
This patch (see attachment) allows for multiple "default packages" to be specified. The classes in these packages will be mapped by their "short class name" (as by ClassUtils.shortClassName(type)). When an alias for a "default package"-class is found it is stored as a simple alias for fast future access.