[Simple-support] Deserializing inherited objects from XML
Brought to you by:
niallg
|
From: Tek W. <tek...@gm...> - 2014-01-15 13:20:51
|
I need this work with this type of XML
<component class="com.abc.Container" type="Container" >
<component class="com.abc.Label" type="Label" name="Label201"/>
<component class="com.abc.Button" type="Button" name="Button202"/>
My class structure is:
@Root(name = "component")
public class com.abc.BaseComponent {
@ElementList(inline = true,required=false)
ArrayList<BaseComponent> childComponents = null;
}
and
@Root(name = "component")
public class Button extends BaseComponent {
Button() {
super();
}
}
@Root(name = "component")
public class Label extends BaseComponent {
Label() {
super();
}
}
@Root(name = "component")
public class Container extends BaseComponent {
Container () {
super();
}
}
So the logic is that the Container can add any other object as long as it
is of BaseComponent type.
On serialization, I do get the desired XML, however I can not deserialize
it back from XML to Objects.
I tried to use @ElementListUnion with listing of each BaseComponent type in
it, that changes the XML structure. Its almost like the format that I need
to support is using attributes and simplexml like to use elements.
Regards
|