xstream icon indicating copy to clipboard operation
xstream copied to clipboard

Using more than one @XStreamAlias annotation for same element

Open wertklop opened this issue 7 years ago • 5 comments

Improvement. I would like to have an implementation that support:

@XStreamAlias("alias1")
@XStreamAlias("alias2")
class ABC{

    @XStreamAlias("field1")
    @XStreamAlias("field2")
    String field;
}

Where xml node has been named any present aliases. Thank's

wertklop avatar Jan 15 '18 10:01 wertklop

You can do this without annotations using the XStream.alias() and XStream.aliasField() methods. However, this is no usual setup and you have to know, that a second alias definition will clobber the first one at serialization time, but will remain active for deserialization.

joehni avatar Jan 15 '18 22:01 joehni

@joehni FWIW, I would also like to see @XStreamAlias be made @Repeatable. Of course, during serialization one of the alias definitions has to be picked, but as long as the choice is deterministic, I think there is not much risk of confusion. And it would really simplify working with types which (unfortunately) have suffered multiple rounds of renaming in the past (you know, naming is a hard problem).

sewe avatar Feb 14 '19 08:02 sewe

@joehni I would like @XStreamAlias to be repeatable too. Clients send us XMLs with different names for the same fields, and we (sadly) have to support this. For example, the following snippets have to be treated identically: <item-ids><item>123</item></item-ids> // lower case field name <item-ids><Item>123</Item></item-ids> // capitalized field name

tetianakh avatar Apr 09 '19 15:04 tetianakh

Quite honestly I don't understand why this got closed so fast. It would be easy to make the annotation repeatable. The currenty state forces you to stray your meta data in annotations and extra-code when you want to have more than one alias. I support the original request. @tetianakh also delivered a scenario which developers find themselves in quite frequently.

bzurmaar avatar Dec 22 '23 10:12 bzurmaar

So I keep it open for now...

joehni avatar Feb 13 '24 23:02 joehni