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:
@@ -90,7 +90,7 @@ public class Streamer
|
|||||||
* does not implement {@link Streamable} and is not one of the basic
|
* does not implement {@link Streamable} and is not one of the basic
|
||||||
* object types (@see {@link ObjectOutputStream}).
|
* object types (@see {@link ObjectOutputStream}).
|
||||||
*/
|
*/
|
||||||
public synchronized static Streamer getStreamer (final Class target)
|
public synchronized static Streamer getStreamer (Class target)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// if we have not yet initialized ourselves, do so now
|
// if we have not yet initialized ourselves, do so now
|
||||||
@@ -98,6 +98,12 @@ public class Streamer
|
|||||||
createStreamers();
|
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);
|
Streamer stream = _streamers.get(target);
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
// make sure this is a streamable class
|
// 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
|
// create our streamer in a privileged block so that it can
|
||||||
// introspect on the to be streamed class
|
// introspect on the to be streamed class
|
||||||
try {
|
try {
|
||||||
|
final Class ftarget = target;
|
||||||
stream = AccessController.doPrivileged(
|
stream = AccessController.doPrivileged(
|
||||||
new PrivilegedExceptionAction<Streamer>() {
|
new PrivilegedExceptionAction<Streamer>() {
|
||||||
public Streamer run () throws IOException {
|
public Streamer run () throws IOException {
|
||||||
return new Streamer(target);
|
return new Streamer(ftarget);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (PrivilegedActionException pae) {
|
} catch (PrivilegedActionException pae) {
|
||||||
|
|||||||
Reference in New Issue
Block a user