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
This commit is contained in:
Michael Bayne
2006-09-12 00:32:06 +00:00
parent ac5951eaa1
commit eb3c6ae9cf
+9 -2
View File
@@ -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<Streamer>() {
public Streamer run () throws IOException {
return new Streamer(target);
return new Streamer(ftarget);
}
});
} catch (PrivilegedActionException pae) {