out.writeString(nvp.getName()); out.writeString(nvp.getValue());
public class MyClass { private static final int CUR_VERSION = 5; private String _value; private void readObject(ObjectInputStream in) { // first value is always the serial version: int dataVersion = in.readInt(); if(dataVersion == CUR_VERSION) { // _value is a String _value = in.readString(); } else { // in older versions, _value was an int _value = String.valueOf(in.readInt()); } } private void writeObject(ObjectOutputStream out) { // always write version first out.writeInt(CUR_VERSION); out.writeString(_value); } }
/** * Writes string without allowing it to be replaced in stream. Used by * ObjectStreamClass to write class descriptor type strings. */ void writeTypeString(String str) throws IOException { int handle; if (str == null) { writeNull(); } else if ((handle = handles.lookup(str)) != -1) { writeHandle(handle); } else { writeString(str, false); } }
/** * Writes string without allowing it to be replaced in stream. Used by * ObjectStreamClass to write class descriptor type strings. */ void writeTypeString(String str) throws IOException { int handle; if (str == null) { writeNull(); } else if ((handle = handles.lookup(str)) != -1) { writeHandle(handle); } else { writeString(str, false); } }
/** * Writes given enum constant to stream. */ private void writeEnum(Enum en, ObjectStreamClass desc, boolean unshared) throws IOException { bout.writeByte(TC_ENUM); ObjectStreamClass sdesc = desc.getSuperDesc(); writeClassDesc((sdesc.forClass() == Enum.class) ? desc : sdesc, false); handles.assign(unshared ? null : en); writeString(en.name(), false); }
/** * Writes given enum constant to stream. */ private void writeEnum(Enum en, ObjectStreamClass desc, boolean unshared) throws IOException { bout.writeByte(TC_ENUM); ObjectStreamClass sdesc = desc.getSuperDesc(); writeClassDesc((sdesc.forClass() == Enum.class) ? desc : sdesc, false); handles.assign(unshared ? null : en); writeString(en.name(), false); }
writeString((String) obj, unshared); } else if (cl.isArray()) { writeArray(obj, desc, unshared);
writeString((String) obj, unshared); } else if (cl.isArray()) { writeArray(obj, desc, unshared);