java - Use annotation other than XstreamAlias to serialize an object with XStream -


i have java class in members annotated xstreamalias annotation. under conditions output same class (and members recursively) different annotations. how can ask xstream use method/class annotations not @xstreamalias annotation?

you cannot make xstream use different annotations, can define different aliases in code.

@xstreamalias("abc") public class abc {     @xstreamalias("bb")     public string a; } 

when serialize above class annotations following xml

<abc>   <bb>something</bb> </abc> 

when disable annotations , define new aliases

xstream xstream = new xstream(); xstream.autodetectannotations(false); xstream.alias("xxx", abc.class); xstream.aliasfield("ccc", abc.class, "a"); 

you different xml output

<xxx>   <ccc>something</ccc> </xxx> 

list of available alias methods:

alias class shorter name used in xml elements.

public void alias(string name, class type) 

alias type shorter name used in xml elements. class assignable type aliased same name.

public void aliastype(string name, class type) 

alias class shorter name used in xml elements. defaultimplementation represents default implementation of type use if no other specified.

public void alias(string name, class type, class defaultimplementation) 

alias package shorter name used in xml elements.

public void aliaspackage(string name, string pkgname) 

create alias field name.

public void aliasfield(string alias, class definedin, string fieldname) 

create alias attribute

public void aliasattribute(string alias, string attributename) 

create alias system attribute. xstream not write system attribute if alias set <code>null</code>. however, not reversible, i.e. deserialization of result fail afterwards , not produce object equal written one.

public void aliassystemattribute(string alias, string systemattributename) 

create alias attribute.

public void aliasattribute(class definedin, string attributename, string alias) 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -