I’m trying to use simplexml to deserialize an object and code that works using java doesn’t work over Android.
The simple class:
@Root
public class GenericContainer
{
@Element
public MainEntity el;
}
That is declared:
GenericContainer genContainer = new GenericContainer();
genContainer.el = new SubClassBEntity(); //SubClassBEntity is a Subclass of MainEntity
Is serialized and generates a xml:
<?xml version='1.0' encoding='utf-8'?>
<genericContainer>
<el class="test.entities.SubClassBEntity>
<x>1</x>
</el>
</genericContainer>
If I try to deserialize the xml using java all goes ok but if I do the same using android I get a crash where exception message is test.entities.SubClassBEntity.
Any idea to fix this problem?
Thanks
The only solution that I found is use
@ElementUnionput all the possibilities inside. It’s a dirty solution because you can have a base class with 50 subclasses and you will have to put all. Automatic refactoring will don’t change the annotations and it will be a piece of error prone code.