I am implementing a sort of mapping between a XSD object into a Parcelable on Android. Everything goes fine except when I have a more complex xsd element which contains a elements which are optional (minOccurs='0' maxOccurs='1').
I need to write my bean constructor with the format:
private Bean (Parcel in) {
super();
this.setId(in.readInd());
this.setComplexData((ComplexClass) in.readParcelable(ComplexClass.class
.getClassLoader()));
this.setComplexData2((ComplexClass2) in.readParcelable(ComplexClass2.class
.getClassLoader()));
}
but both the complex data is optional.
When I had just one optional data, I was using:
if(in.dataAvail() >0)
this.setComplexData((ComplexClass) in.readParcelable(ComplexClass.class
.getClassLoader()));
But if both are optional, I cant do that. Therefore, I was wondering if there is some way to identify what is the object within the parcelable, some sort of way to check the class signature? In that sense, I could check if the data is ComplexClass1 or 2 and do the read.