I'm committing the attached patch which adds enum serialization support
to ObjectOutputStream.

Changelog:

2006-04-02  Andrew John Hughes  <[EMAIL PROTECTED]>

        * java/io/ObjectOutputStream.java:
        (writeObject(Object)): Added enum support.
        (writeClassDescriptor(ObjectStreamClass)): Likewise.
        * java/io/ObjectStreamClass.java:
        (isEnum()): New package-private method.
        (setFlags(Class)): Added enum support.
        * java/io/ObjectStreamConstants.java:
        (SC_ENUM): Added.

-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

If you use Microsoft Office, support movement towards the end of vendor lock-in:
http://opendocumentfellowship.org/petition/

"Value your freedom, or you will lose it, teaches history. 
`Don't bother us with politics' respond those who don't want to learn." 
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: java/io/ObjectOutputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/ObjectOutputStream.java,v
retrieving revision 1.46.2.13
diff -u -3 -p -u -r1.46.2.13 ObjectOutputStream.java
--- java/io/ObjectOutputStream.java     26 Mar 2006 20:08:15 -0000      
1.46.2.13
+++ java/io/ObjectOutputStream.java     2 Apr 2006 20:38:13 -0000
@@ -259,7 +259,17 @@ public class ObjectOutputStream extends 
            ObjectStreamClass osc = 
ObjectStreamClass.lookupForClassObject(clazz);
            if (osc == null)
              throw new NotSerializableException(clazz.getName());
-           
+
+           if (osc.isEnum())
+             {
+               /* TC_ENUM classDesc newHandle enumConstantName */
+               realOutput.writeByte(TC_ENUM);
+               writeObject(osc);
+               assignNewHandle(obj);
+               writeObject(((Enum) obj).name());
+               break;
+             }
+
            if ((replacementEnabled || obj instanceof Serializable)
                && ! replaceDone)
              {
@@ -438,7 +448,10 @@ public class ObjectOutputStream extends 
       {
         realOutput.writeByte(TC_CLASSDESC);
         realOutput.writeUTF(osc.getName());
-        realOutput.writeLong(osc.getSerialVersionUID());
+       if (osc.isEnum())
+         realOutput.writeLong(0L);
+       else
+         realOutput.writeLong(osc.getSerialVersionUID());
         assignNewHandle(osc);
 
         int flags = osc.getFlags();
Index: java/io/ObjectStreamClass.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/ObjectStreamClass.java,v
retrieving revision 1.34.2.8
diff -u -3 -p -u -r1.34.2.8 ObjectStreamClass.java
--- java/io/ObjectStreamClass.java      10 Jan 2006 15:59:40 -0000      1.34.2.8
+++ java/io/ObjectStreamClass.java      2 Apr 2006 20:38:13 -0000
@@ -226,6 +226,12 @@ public class ObjectStreamClass implement
     return (flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0;
   }
 
+  // Returns true iff the class that this ObjectStreamClass represents
+  // implements Externalizable.
+  boolean isEnum()
+  {
+    return (flags & ObjectStreamConstants.SC_ENUM) != 0;
+  }
 
   // Returns the <code>ObjectStreamClass</code> that represents the
   // class that is the superclass of the class this
@@ -594,6 +600,9 @@ outer:
 
     if (writeObjectMethod != null)
       flags |= ObjectStreamConstants.SC_WRITE_METHOD;
+
+    if (cl.isEnum() || cl == Enum.class)
+      flags |= ObjectStreamConstants.SC_ENUM;
   }
 
 
@@ -603,7 +612,7 @@ outer:
   {
     SetAccessibleAction setAccessible = new SetAccessibleAction();
 
-    if (!isSerializable() || isExternalizable())
+    if (!isSerializable() || isExternalizable() || isEnum())
       {
        fields = NO_FIELDS;
        return;
Index: java/io/ObjectStreamConstants.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/ObjectStreamConstants.java,v
retrieving revision 1.12.2.3
diff -u -3 -p -u -r1.12.2.3 ObjectStreamConstants.java
--- java/io/ObjectStreamConstants.java  29 Mar 2006 21:34:57 -0000      1.12.2.3
+++ java/io/ObjectStreamConstants.java  2 Apr 2006 20:38:13 -0000
@@ -98,6 +98,7 @@ public interface ObjectStreamConstants
   byte SC_SERIALIZABLE = 0x02;
   byte SC_EXTERNALIZABLE = 0x04;
   byte SC_BLOCK_DATA = 0x08;
+  byte SC_ENUM = 0x10;
 
   SerializablePermission SUBSTITUTION_PERMISSION
     = new SerializablePermission("enableSubstitution");

Attachment: signature.asc
Description: Digital signature

Reply via email to