This would have saved me soooo much time. Serializer's

single-arg registerClass() method now throws an exception
if the object is not marked Serializable.  Internally,
the package-load stuff uses the new alternate method that
allows safe non-exception throwing registration since it's
hitting it with every class in a package.
Interestingly enough, messages will still get written out 
because of some questionable code in writeClassAndObject()...
but it won't be read as anything but null despite its
40+ bytes of data.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7121 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 14 years ago
parent 0a369b96d8
commit 99a21a8c1d
  1. 9
      engine/src/networking/com/jme3/network/serializing/Serializer.java

@ -128,6 +128,10 @@ public abstract class Serializer {
} }
public static SerializerRegistration registerClass(Class cls) { public static SerializerRegistration registerClass(Class cls) {
return registerClass(cls, true);
}
public static SerializerRegistration registerClass(Class cls, boolean failOnMiss) {
if (cls.isAnnotationPresent(Serializable.class)) { if (cls.isAnnotationPresent(Serializable.class)) {
Serializable serializable = (Serializable)cls.getAnnotation(Serializable.class); Serializable serializable = (Serializable)cls.getAnnotation(Serializable.class);
@ -151,6 +155,9 @@ public abstract class Serializer {
return reg; return reg;
} }
if (failOnMiss) {
throw new IllegalArgumentException( "Class is not marked @Serializable:" + cls );
}
return null; return null;
} }
@ -172,7 +179,7 @@ public abstract class Serializer {
SerializerRegistration[] registeredClasses = new SerializerRegistration[classes.size()]; SerializerRegistration[] registeredClasses = new SerializerRegistration[classes.size()];
for (int i = 0; i != classes.size(); ++i) { for (int i = 0; i != classes.size(); ++i) {
Class clz = classes.get(i); Class clz = classes.get(i);
registeredClasses[i] = registerClass(clz); registeredClasses[i] = registerClass(clz, false);
} }
return registeredClasses; return registeredClasses;
} catch (Exception e) { } catch (Exception e) {

Loading…
Cancel
Save