I am using the Simple XML Serialization library in my Android app for parsing and mapping an XML response from a web service to objects, like so:
@Root(name="root_tag", strict=false)
public class XMLRequest {
@Path("a/b")
@ElementList(name="routeList")
private List<Route> routes;
public ArrayList<Route> getRoutes() {
return new ArrayList<Route>(routes);
}
}
I have several more dependent model-classes (like Route
) written in a similar way with the proper annotations, the parsing an mapping works fine.
I now want to pass the Route
list to a new fragment and display it in a ListView
. There are quite a lot of variables in several more model-classes, so I just wanted those classes to implement Parcelable
and pass the list like this to my fragment:
public static ResultFragment newInstance(ArrayList<Route> routes) {
ResultFragment fragment = new ResultFragment();
Bundle args = new Bundle();
args.putParcelableArrayList(ROUTE_LIST_KEY, routes);
fragment.setArguments(args);
return fragment;
}
My problem: I can't let the model-classes implement Parcelable
, that breaks the mapping with the Simple framework. I also don't want to write new Parcelable model objects, that's redundant work which increases when I have to adjust my model classes. Putting every single variable in the bundle is also not an option, there are too many and also too many lists.
What I tried so far as a work-around is to pass the result string to the fragment (instead of the objects) and do the parsing and mapping there. But the process takes a while and I only want to do it once and just use my model objects from there on.
Does anyone have a suggestion how I can solve this? I would really like to keep the Simple
mapping, because manual parsing and mapping via XMLPull would be a lot more work. Thanks!