Are there any negative implications or known gotchas with storing static data (e.g. hashmaps, lists, objects) in Android as Java serialization streams?
By static data I mean data which does not change over time, not that the data is going to be in a static variable.
The serialization file is pre-generated and embedded into the app as a raw file resource (e.g. app/src/main/res/raw/my_serialized_data.ser
) and then read with:
InputStream myData = context.getResources().openRawResource(R.raw.my_serialized_data);
ObjectInputStream ois = new ObjectInputStream(charMap);
myTable = (LinkedHashMap<String, String>) ois.readObject();
ois.close();
Apart from human readability issues I see no disadvantages since reading a serialised object from a file is bound to be faster than parsing data from something like a CSV or a SQLite database.
I have found this approach been used in some existing apps and currently consider using this approach in my own code. The motivation is that my data is bigger than 64K and putting it into a hashmap would require splitting the initialization code into methods that are maximum 64K in size.