java - Mapping Inheritance with XStream -


when marshaling classes inheritance child class data persisted.

for example, code:

public class test {      static class person {         string name;     }      static class employee extends person {         string job;     }      public static void main(string[] args) {         employee me = new employee();         me.name = "sam";         me.job = "developer";         xstream xstream = new xstream();         xstream.alias("employee", employee.class);         string xml = xstream.toxml(me);         system.out.println(xml);     } } 

my output looks like:

<employee>   <job>developer</job> </employee> 

how can xstream output parent class data?

you have switch newer xstream version. ran code 1.2.2 , result:

<employee>   <job>developer</job>   <name>sam</name> </employee> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -