² 00 07: 域名字的长度;
² 76 65 72 73 69 6F 6E 78 70: version,域名字描述version;块的结束标记:见颜色:0x78: TC_ENDBLOCKDATA,对象块结束的标志。0x70:TC_NULL,没有超类了。
输出域的值信息,见颜色:² 00: 域值为00;² 64: 域值为100; 5.2 复杂对象的序列化介绍package com.asc.alibaba.base;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
class Contain implements Serializable {
publicintcontainVersion = 11;
}
class Parent implements Serializable {
publicintparentVersion = 10;
}
publicclass SerialTest extends Parent implements Serializable {
publicint version = 66;
public Contain con = new Contain();
publicint getVersion() {
returnversion;
}
publicstaticvoid main(String[] args) throws IOException {
FileOutputStream fos = new FileOutputStream("temp1.out");
ObjectOutputStream oos = new ObjectOutputStream(fos);
SerialTest testSerialize = new SerialTest();
oos.writeObject(testSerialize);
oos.flush();
oos.close();
FileInputStream fis = new FileInputStream("temp1.out");
byte[] bb = newbyte[200];
while (fis.read(bb) != -1) {
for (byte b : bb) {
System.out.print(Integer.toHexString(b));
System.out.print(" ");
}
}
}
}
这个例子中SerialTest类实现了Parent超类,内部还持有一个Container对象。序列化后的格式如下: