Write an algorithm in pseudocode to describe deserialization of the serialized form produced by the algorithm. Hint: use reflection to create a class from its name, to create a constructor from its parameter types and to create a new instance of an object from the constructor and the argument values.
What will be an ideal response?
Whenever a handle definition is read, i.e. a class_info, handle correspondence or an object, handle correspondence, store the pair by method map. When a handle is read look it up to find the corresponding class or object.
```
Object deserialize(byte [] stream) { Constructor aConstructor;
read class_name and class_handle;
if (class_information == null) aConstructor = lookup(class_handle);
else {
Class cl = Class.forName(class_name); read number (n) of instance variables Class parameterTypes[]= new Class[n]; for (int i=0 to n-1) {
read name and class_name of instance variable i parameterTypes[i] = Class.forName(class_name);
}
aConstructor = cl.getConstructor(parameterTypes);
map(aConstructor, class_handle);
}
if (next item in stream is object_handle) o = lookup(object_handle);
else {
Object args[] = new Object[n];
for (int i=0 to n-1) {
if (next item in stream is primitive) args[i] = read value else args[i] = deserialize(//rest of stream)
}
Object o = cnew.newInstance(args); read object_handle from stream map(object, object_handle)
return o;
}
}
```
You might also like to view...
The ________ is the temporary storage area that is used when copying or moving information from one place to another
Fill in the blank(s) with correct word
Which of the following functions calculates the total of a column or row of cells?
A. TOTAL B. SUM C. SUMCOL D. SUMROW