Details
-
Type: Bug
-
Status: Closed
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.2
-
Component/s: None
-
Labels:None
Description
The current implementation of the AttributeAliasConverter works only, if the given alias matches the field name:
public void testWithAliasAndCustomConverter()
{ One one = new One(); one.two = new Two(); one.id = new ID("hullo"); xstream.aliasAttribute("id", ID.class); xstream.registerConverter(new MyIDConverter()); String expected = "<com.thoughtworks.acceptance.AttributeAliasTest-One id=\"hullo\">\n" + " <two/>\n" + "</com.thoughtworks.acceptance.AttributeAliasTest-One>"; assertBothWays(one, expected); }Setting
xstream.aliasAttribute("uid", ID.class);
showa, that the marshalled XML still just have an "id" attribute instead of the attribute "uid" and additionally will fail with an NPE unmarshalling this XML again. Basically it does make sense to support "XStream.aliasField(ID.class)". In this case the attribute name is always taken from the filed name.
See also http://thread.gmane.org/gmane.comp.java.xstream.user/1665 for a use case.
Implemented attributeAlias(type), attributeAlias(name, type) will only support the alias, if the field name matches the attribute name.