Simple-XML and class attribute issues when dealing with multiple projects

Complex problem here, since it involves also Java for Android. I’ll ask anyway.

I’m trying to use SimpleXML to serialize/deserialize data that must be used by a main program (running on Android platform) and an editor (running on a Desktop platform).

The editor extends a ParentClass (contained in a “common libraries” project) with a ChildClass to give it more functionality (such as graphic properties and so on).

I would like to not save any reference to ChildClass in the XML files, to avoid circular dependencies problems between projects.

This is a summary of how the projects are structured:
First project(EDITOR)


// I project (DESKTOP EDITOR, requires COMMON CLASSES to build)

@Element(name = "Tile2", type = Tile2.class, required = false)
public class ChildClass extends ParentClass {
    BufferedImage thumbnailToDisplay = null;
    // Additional methods and variables that are not annotated, 
    // since they don't have to go into the XML, like these ones 
    public void generateThumb() {
        getGraphics(super.imageName);
    }

    public BufferedImage getGraphics(String imgName) {
        // various graphic routines
    }
}

public class EditorWindow(Container contentToModify) {
    private mCont;
    // Constructor
    public EditorWindow(Container contentToModify) {
        this.mCont = contentToModify;
        this.initialize();
    }
    // Various methods 
    // Must access all the elements in contentToModify 
    // as if their type is ChildClass 
    public void initialize() {
        for (int i = 0; i < this.mCont.getItems().size(); i++)
            ChildClass tmp = (ChildClass)this.mCont.getItems().get(i);
            tmp.generateThumb();
    }
 }

 // This is the main class, that starts the editor GUI, initializes stuffand so on
 public class Gui() { 
    Container mainContainer;
    EditorWindow edWin;

    public static main() {
        mainContainer = Xml_IO.XmlLoad(new File("XmlPath/filename"));
        edWin = new EditorWindow(mainContainer);

        // Stuff that could modify the content of mainContainer
        File file = saveFile.getSelectedFile();
        XML_IO.XmlSave(file, this.mainContainer);
    }
 }

Second project (common libraries)

// II project (COMMON CLASSES)
@Root(strict=false)
public class ParentClass {
    @Attribute
    float size;
    @Attribute
    float position; 
    @Element
    String imageName;
}
@Root(name = "Container", strict=false)
public class Container {
    @ElementList(type = parentClass.class, required = false,inline=true, entry="container")
    private ArrayList<ParentClass> mItems = new ArrayList<ParentClass>();

    public ArrayList<XItem> getItems() {
        return mItems;
    }

}

public class Xml_IO {
    // Deserializer method (could be moved to I project(DESKTOP EDITOR), if needed)
    public static Container XmlLoad(File inputXmlFile) {
        Container tmpContainer = new Container();
        Serializer serializer = new Persister();

        try {
            tmpContainer = serializer.read(Container.class, inputXmlFile);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return tmpContainer;
    }

    // Serializer method (could be moved to I project(DESKTOP EDITOR), if needed)
    public static void XmlSave(File outputXmlFile, Container containerToSave) {
        Format format = new Format(
                "<?xml version=\"1.0\" encoding= \"UTF-8\" ?>");
        Serializer serializer = new Persister(format);

        try {
            serializer.write(containerToSave, outputXmlFile);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Third project (Android application)


// III project (ANDROID MAIN PROGRAM, requires COMMON CLASSES to build, must NOT require EDITOR to build) 
public class Activity extends CustomActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) { 

        // Custom serializer 
        Container contentToRead = new Container();
        Serializer serializer = new Persister();

        try {
            contentToRead = serializer.read(Container.class, this.getResources().openRawResource(R.raw.xml_resource), false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

This is instead an example of the XML generated with current setup:

<?xml version="1.0" encoding= "UTF-8" ?>
<Container>
    <ParentClass class="project1.ChildClass" size="1.0" position="2.5">
       <mImage>image1</mImage>
    </ParentClass>
    <ParentClass class="project1.ChildClass" size="2.0" position="1.5">
       <mImage>image2</mImage>
    </ParentClass>
</Container>

The I/O on the editor works well, but if I try to deserialize the XML on Android, it fails with the following error: java.lang.ClassNotFoundException: Didn’t find class “project1.ChildClass” on path: DexPathList[dexElements=[zip file “/mnt/asec/projectname/pkg.apk”],nativeLibraryDirectories=[/mnt/asec/projectname/lib, /vendor/lib, /system/lib]]

This is what I tried so far:

1.I tried the @ElementListUnion annotation, as suggested here, but it does not remove the class attribute.
2.tried to inline the list, as suggested here, but the class attribute did not disappear
3.tried to understand how to implement a Converter, as suggested here but I cannot figure out how to solve the problems of circular dependencies it would introduce
4.tried to manually remove the class="project1.ChildClass" attributes: the Android application in this case works, but the editor stops importing XML files, since it would not be possible to cast the ParentClass into a ChildClass. Even if I would solve that issue, it would still save the XML file with the "class" attribute

What I would like is to serialize XML files from the editor without any reference to the ChildClass (so the Android application could read them), but to deserialize the ParentClass items as ChildClass into the editor.

remember the golden words: “composition over inheritance”