It is first time when I am doing serialization/deseraialization and I have an issue what I cannot understand. So I have an employee class:
public class Employee implements Serializable{
private static final long serialVersionUID = -8987739485808870716L;
public String firstName;
public String lastName;
public int phoneNumber;
public ArrayList<Skill> empSkillAry = new ArrayList<Skill>(); //
Skill class:
public class Skill implements Serializable {
private static final long serialVersionUID = 4862257193587272698L;
public int skillID;
public String skillName;
Schedule class:
public class Schedule implements Serializable {
private static final long serialVersionUID = 781243452337862636L;
String Name;
int CsID;
public ArrayList<Skill> skillRequiredAry = new ArrayList<Skill>();
To empSkillAry and skillRequiredAry are added skill object. If empSkillAry contains all skillRequiredAry objects, employee can be assigned to the shift. Lets say, employee has skill 1 and schedule also has skill 1. before serialization when comparing both arrays I get a positive result, however after deserialization it is negative. Is there something wrong whith my serialization and deserialization code? Here it is:
private static void deserializeAry(ArrayList arrayToDesirialize, String filePath){
try {
FileInputStream fileIn = new FileInputStream(filePath);
ObjectInputStream in = new ObjectInputStream(fileIn);
arrayToDesirialize = (ArrayList) in.readObject();
System.out.println(arrayToDesirialize);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void serializeAry(ArrayList arrayToSerialize, String filePath){
try {
FileOutputStream fileOut = new FileOutputStream(filePath);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
System.out.println(arrayToSerialize.toString());
out.writeObject(arrayToSerialize);
fileOut.close();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}