I have a .ser file. I know its class but I do not know what attributes the object contains. Is there any method that can sort of 'deserialize' it? Or it's just impossible?
1 Answer
ObjectInputStream in = new ObjectInputStream(new FileInputStream("config/quarks.ser"));
int count = 0;
try {
while (true) {
count++;
try {
Object obj = in.readObject();
System.out.println(obj);
} catch (ClassNotFoundException e) {
System.out.println("can't read obj #" + count + ": " + e);
}
}
} catch (EOFException e) {
} finally {
in.close();
}
-
I tried this already but since i have no idea about what the attributes of the objects are, it just throws an InvalidClassException. At first it threw a ClassNotFoundException. Then I created a Parameter class which is empty and then there, it started throwing the InvalidClassException. I am asking is if it is possible to like "dissect" what the object's attributes really are since I have no idea about what the class Parameter contains.I just know that the .ser file is an object of class Parameter. Anyway, thank you for the code snippet :) Commented Mar 17, 2014 at 13:19
-
i tried it in eclipse ....it working fine.... i got outputlike [up, down, strange, charm, top, bottom, sudo]– SUBZCommented Mar 17, 2014 at 14:44
-
Uhm hello again, I tried to compile and run it in terminal but it goes blank now.Nothing printed just nothing. I assume it goes straight to the catch block. Does this only work on eclipse? Commented Mar 18, 2014 at 7:39
-
try to print anything inside catch block if EOE comes because of no serialised object in your .ser file– SUBZCommented Mar 18, 2014 at 9:32
-
I already deserialized the file. Turns out we just need to ask for the class that is contained in the ser file. Thank you anyway! Your method worked for me after knowing what class we are deserializing Commented Mar 30, 2014 at 17:15