I would like to save an array of objects that is custom as a file and re-read it back as an array of objects on program start in java. If I could also save it as JSON, it would be nice. I have tried some common methods but I get a error saying that my array is not serialiazable.
class ArrayOfObjects {
public static void main (String[] args) throws Exception {
Students[] studentArray = new Students[3];
studentArray[0] = new Students();
studentArray[0].age = 18;
studentArray[0].name = "Jones";
studentArray[1] = new Students();
studentArray[1].age = 21;
studentArray[1].name = "David";
studentArray[2] = new Students();
studentArray[2].age = 15;
studentArray[2].name = "Jeremy";
}
}
class Students {
int age;
String name;
}