I have a class that implements Serializable
and has a following structure:
public class WorkWishesForm implements Serializable {
//================================================================================
// Переменные
//================================================================================
public ArrayList<OfferTrade> offerTradeArray;
public int salary;
public OperatingSchedule operatingSchedule;
public boolean businessTripsAllowed;
public ArrayList<Region> regionArray;
//================================================================================
// Конструктор
//================================================================================
public WorkWishesForm() {
}
}
Class OperatingSchedule
also implements Serializable, but it's state is not saved for some reason after serialization of WorkWishesForm
class. This is it's structure:
public class OperatingSchedule extends NamedObject implements Serializable {
//================================================================================
// Конструктор
//================================================================================
public OperatingSchedule(JSONObject jsonObject, Context context) {
super(context);
try {
name = jsonObject.getString("name");
id = jsonObject.getInt("id");
}
catch (JSONException e) {
e.printStackTrace();
}
}
public OperatingSchedule() {
super();
}
//================================================================================
// Другое
//================================================================================
public String toString()
{
return this.name;
}
}
And here is NamedObject:
public class NamedObject {
//================================================================================
// Переменные
//================================================================================
protected int id;
protected String name;
protected Context context; //Контекст часто бывает нужен для обращения к ресурсам, например, строкам
//================================================================================
// Конструкторы
//================================================================================
public NamedObject (Context context) {
this.context = context;
}
public NamedObject() {
}
//================================================================================
// Геттеры и сеттеры
//================================================================================
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
//================================================================================
// Другое
//================================================================================
public static ArrayList<String> stringListFromObjectList (ArrayList<NamedObject> objectList)
{
ArrayList<String> stringList = new ArrayList<String>();
for (NamedObject obj : objectList) {
stringList.add(obj.getName());
}
return stringList;
}
}
If I implement Serializable
in NamedObject
, class WorkWishesForm
becomes completely Unserializable (error occurs). When I don't implement, the state of OperatingSchedule
is not saved.
What should I do, to make it save?