Guardar object en la memory interna en android (kotlin)

He estado intentando save una list en la memory interna para Android, sin embargo, tengo algunos problemas. Aquí está mi código para save y cargar la list:

Ahorro

saveStateList.add(saveState) val fos: FileOutputStream var oos: ObjectOutputStream? = null var allSaveStates :AllSaveStates = AllSaveStates() allSaveStates.saveStateList=saveStateList try { fos = activity.applicationContext.openFileOutput("saves", Context.MODE_PRIVATE) oos = ObjectOutputStream(fos) oos.writeObject(allSaveStates) oos.close() } catch (e: Exception) { } finally { if (oos != null) try { oos.close() } catch (e: Exception) { } } 

Cargando

  val fis: FileInputStream var ois: ObjectInputStream? = null try { println("loading saves") fis = activity.applicationContext.openFileInput("saves") ois = ObjectInputStream(fis) var allSaveStates :AllSaveStates = (ois.readObject()) as AllSaveStates saveStateList=allSaveStates.saveStateList ois.close() } catch (e: Exception) { println("error loading saves") } finally { if (ois != null) try { ois.close() } catch (e: Exception) { println("error closing input stream") } } 

Clase AllSaveStates

 class AllSaveStates : Serializable { var saveStateList: MutableList<SaveState> = mutableListOf() } 

Clase SaveState

 class SaveState : Serializable{ var name : String = "" var mapSize : Int = 0 var startDay : Int = 0 var startMonth : Int = 0 var startYear : Int = 0 var currentMinutes : Int = 0 var currentHour : Int = 0 var currentDay : Int = 0 var currentMonth : Int = 0 var currentYear : Int = 0 var newsList: MutableList<String> = mutableListOf<String>() var itemList : MutableList<Item> = mutableListOf() lateinit var generator : WorldGenerator } 

Esta línea de código me da NotSerializableException para SaveState si elimino la cláusula try para la carga:

 var allSaveStates :MutableList<SaveState> = (ois.readObject()) as MutableList<SaveState> 

¡Gracias por adelantado!