java - Is it possible to implicitly add object fields to XML using XStream? -


i have convert sorted set of objects of type organization xml file. said type contains, along primitive types , string objects, other reference type objects.

here fields of organization:

string orgname; double capital; individual generaldirector; investor investor; 

next comes investor:

individual name; double sharespercentage; 

and individual:

string firstname; string lastname; 

as can see, both organization , investor contain references objects of type individual.

problem is, need both firstname , lastname displayed in xml organization objects, , lastname investor objects, omitting firstname wouldn't work.

i want omit <'generaldirector'> , <'investor'> tags output, leave content in separate tags, in:

    <organization>         <orgname>dummy solutions</orgname>         <capital>50000</capital>         <dirfirstname>jacob</dirfirstname>         <dirlastname>smith</dirlastname>         <investor>             <lastname>johnson</lastname>             <sharepercentage>5.13</sharepercentage>         </investor>     </organization> 

but xstream converts in following way:

  <organization>       <orgname>dummy solutions</orgname>       <generaldirector>           <firstname>jacob</firstname>           <lastname>smith</lastname>       </generaldirector>       <capital>50000</capital>       <investor>           <name>               <firstname>notspecified</firstname>               <lastname>johnson</lastname>           </name>           <sharespercentage>5.13</sharespercentage>       </investor>   </organization> 

how can rid of generaldirector , investor's name tags without removing content? know there way collections, reference object fields?
, there way display both firstname , lastname individual contained in organization, not in investor?

turns out impossible quite way imagined.

however, solution problem comes in form of custom converter, implements converter interface xstream package. inside such converter 1 can specify way serialize/deserialize particular class of objects.

upon doing solution easy registering specified converter in current xstream instance, so:

xstream xstream = new xstream(); xstream.registerconverter(new yourcustomconverter()); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -