diff --git a/engine/src/networking/com/jme3/network/serializing/Serializer.java b/engine/src/networking/com/jme3/network/serializing/Serializer.java index 1856038f7..a7d20da54 100644 --- a/engine/src/networking/com/jme3/network/serializing/Serializer.java +++ b/engine/src/networking/com/jme3/network/serializing/Serializer.java @@ -61,6 +61,7 @@ public abstract class Serializer { private static final Map idRegistrations = new HashMap(); private static final Map classRegistrations = new HashMap(); + private static final List registrations = new ArrayList(); private static final Serializer fieldSerializer = new FieldSerializer(); private static final Serializer serializableSerializer = new SerializableSerializer(); @@ -167,7 +168,12 @@ public abstract class Serializer { return nextAvailableId--; } - protected static SerializerRegistration registerClassForId( short id, Class cls, Serializer serializer ) { + /** + * Directly registers a class for a specific ID. Generally, use the regular + * registerClass() method. This method is intended for framework code that might + * be maintaining specific ID maps across client and server. + */ + public static SerializerRegistration registerClassForId( short id, Class cls, Serializer serializer ) { SerializerRegistration reg = new SerializerRegistration(serializer, cls, id); @@ -178,6 +184,10 @@ public abstract class Serializer { serializer.initialize(cls); + // Add the class after so that dependency order is preserved if the + // serializer registers its own classes. + registrations.add(reg); + return reg; } @@ -285,6 +295,10 @@ public abstract class Serializer { return getSerializerRegistration(cls, failOnMiss).getSerializer(); } + public static Collection getSerializerRegistrations() { + return registrations; + } + public static SerializerRegistration getExactSerializerRegistration(Class cls) { return classRegistrations.get(cls); }