List of usage examples for java.io ObjectStreamClass getSerialVersionUID
public long getSerialVersionUID()
From source file:GetSerVersUID.java
public static void main(String[] av) throws Exception { // First we construct a Class object for the given class Class cl = Class.forName("Candidate"); // Then an ObjectStreamClass for the given class ObjectStreamClass ocl = ObjectStreamClass.lookup(cl); // And use the ObjectStreamClass to get the Class' // unique SerialVersionUID System.out.println("For class " + cl); System.out.println("static final long serialVersionUID = " + ocl.getSerialVersionUID() + "L;"); // must be long // And just for reference... System.out.println("(Must range from " + Long.MIN_VALUE + " to " + Long.MAX_VALUE + ".)"); }
From source file:ClassVersionInfo.java
public ClassVersionInfo(String name, ClassLoader loader) throws ClassNotFoundException { this.name = name; Class c = loader.loadClass(name); CodeSource cs = c.getProtectionDomain().getCodeSource(); if (cs != null) location = cs.getLocation();//w w w . j a v a2 s . c o m if (c.isInterface() == false) { ObjectStreamClass osc = ObjectStreamClass.lookup(c); if (osc != null) { serialVersion = osc.getSerialVersionUID(); try { c.getDeclaredField("serialVersionUID"); hasExplicitSerialVersionUID = true; } catch (NoSuchFieldException e) { hasExplicitSerialVersionUID = false; } } } }
From source file:com.espertech.esper.util.ObjectInputStreamWithTCCL.java
@Override public Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { if (log.isDebugEnabled()) { log.debug("Resolving class " + desc.getName() + " id " + desc.getSerialVersionUID() + " classloader " + Thread.currentThread().getContextClassLoader().getClass()); }/*from ww w . j a v a 2 s . c om*/ ClassLoader currentTccl = null; try { currentTccl = Thread.currentThread().getContextClassLoader(); if (currentTccl != null) { return currentTccl.loadClass(desc.getName()); } } catch (Exception e) { } return super.resolveClass(desc); }