From eb3c6ae9cf31a6db46c0fa32385fd6e2d3cd043d Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 12 Sep 2006 00:32:06 +0000 Subject: [PATCH] A particular enum value may actually be a derived class of the declared enum type, but we don't really want to pollute our class <-> id mapping with a bunch of extra fiddly enum classes, so we stream all enums as instances of their declared type and let Enum.valueOf() map back to the custom derived type when it creates an instance during deserialization. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4370 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/java/com/threerings/io/Streamer.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/io/Streamer.java b/src/java/com/threerings/io/Streamer.java index d94ee08a3..de8dc8b2a 100644 --- a/src/java/com/threerings/io/Streamer.java +++ b/src/java/com/threerings/io/Streamer.java @@ -90,7 +90,7 @@ public class Streamer * does not implement {@link Streamable} and is not one of the basic * object types (@see {@link ObjectOutputStream}). */ - public synchronized static Streamer getStreamer (final Class target) + public synchronized static Streamer getStreamer (Class target) throws IOException { // if we have not yet initialized ourselves, do so now @@ -98,6 +98,12 @@ public class Streamer createStreamers(); } + // if the target class is an enum, convert it from its potentially + // enum-value specific class to the main class for that enum + if (target.isEnum()) { + target = target.getDeclaringClass(); + } + Streamer stream = _streamers.get(target); if (stream == null) { // make sure this is a streamable class @@ -114,10 +120,11 @@ public class Streamer // create our streamer in a privileged block so that it can // introspect on the to be streamed class try { + final Class ftarget = target; stream = AccessController.doPrivileged( new PrivilegedExceptionAction() { public Streamer run () throws IOException { - return new Streamer(target); + return new Streamer(ftarget); } }); } catch (PrivilegedActionException pae) {