Example usage for java.io ObjectStreamClass getSerialVersionUID

List of usage examples for java.io ObjectStreamClass getSerialVersionUID

Introduction

In this page you can find the example usage for java.io ObjectStreamClass getSerialVersionUID.

Prototype

public long getSerialVersionUID() 

Source Link

Document

Return the serialVersionUID for this class.

Usage

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);
}