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
Post a Comment