Search code examples
javaserializationdeserializationxstream

Xstream toXml not serializing base class


I have a class with the following structure which i am trying to serialize using Xstream

public class Child extends Parent implements Serializable {
   private String prop1;
   private String prop2;
   // some getter setters
}

Class parent looks like this

 public class Parent implements Serializable {
   private String prop3;
   private String prop4;
   // some getter setters
}

I am trying to serialize the Child class like this.

    Child child = new Child();
    child.setProp1("test desc");
    child.setProp2("test name");
    child.setProp3("xyz");
    child.setProp4(true);

    XStream xstream = new XStream();
    String xmlData = xstream.toXML(virtualTerminalProfile);

but somehow the xml formed is like following

<com.company.Child>
  < prop1>test name</prop1>
  <prop2>test desc</prop2>
</com.company.Child>

I am not seeing prop3 and prop4 in the xml.

I am not sure what i am missing ?

I am using xstream 1.4.4


Solution

  • It got resolved after upgrading to xstream version 1.4.10. May be its a bug in 1.4.4. I did check the release notes but couldn't find anything related to this.