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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -