javaserializationserialversionuid

Find serialver for class with reference to java.sql.Timestamp


I have a simple class with reference to java.sql.Timestamp. Any class with a reference to this class doesn't give serialver unique id. For example, I am not able to find serial version id for java.sql.Timestamp or the class which refers to this.

serialver -classpath . java.sql.Timestamp 

error: Class java.sql.Timestamp not found.

If I have reference to java.sql.Timestamp in MyCustomPOJO in jar custom.jar

serialver -classpath custom.jar com.org.domain.MyCustomPOJO 
Exception in thread "main" java.lang.NoClassDefFoundError: com/org/domain/MyCustomPOJO
    at java.base/java.lang.Class.getDeclaredFields0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3297)
    at java.base/java.lang.Class.getDeclaredField(Class.java:2608)
    at java.base/java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:246)
    at jdk.compiler/sun.tools.serialver.SerialVer.main(SerialVer.java:188)
    Caused by: java.lang.ClassNotFoundException: java.sql.Timestamp
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    ... 31 more

Any one know how to find serialversion id for java.sql.Timestamp Or custom class which has reference to Timestamp?


Solution

  • Since Java 9, Java classes have been organized into modules. See Java Platform Module System at Wikipedia.

    By default, the only module visible to a Java runtime is java.base. serialver does not see other modules, such as the java.sql module that contains the Timestamp class.

    You can tell serialver to include other modules by using -J to pass a java command-line option:

    serialver -J--add-modules=java.sql -classpath custom.jar com.org.domain.MyCustomPOJO