`
leonzhx
  • 浏览: 794176 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Finding serialVersionUID of serialized object

    博客分类:
  • Java
 
阅读更多

Question: Is there a way to determine the generated serialVersionUID of a serialized Java object?

The problem is that I serialized an object without explicitely specifying the serialVersionUID . Now the deserialization process complains about class incompatibilities. However I didn't change the class in a way which would make it incompatible. So I assume that it is enough to specify the serialVersionUID serialVersionUID in the class as it is stored in the object data. In order to do this I need to read the from the serialized data.


Answer:


1)

You can do this by extending ObjectInputStream :

public class PrintUIDs extends ObjectInputStream { 
 
  public PrintUIDs(InputStream in) throws IOException { 
    super(in); 
  } 
 
  @Override 
  protected ObjectStreamClass readClassDescriptor() throws IOException, 
      ClassNotFoundException { 
    ObjectStreamClass descriptor = super.readClassDescriptor(); 
    System.out.println("name=" + descriptor.getName()); 
    System.out.println("serialVersionUID=" + descriptor.getSerialVersionUID()); 
    return descriptor; 
  } 
 
  public static void main(String[] args) throws IOException, 
      ClassNotFoundException { 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    ObjectOutputStream oos = new ObjectOutputStream(baos); 
    List<Object> list = Arrays.asList((Object) new Date(), UUID.randomUUID()); 
    oos.writeObject(list); 
    oos.close(); 
    InputStream in = new ByteArrayInputStream(baos.toByteArray()); 
    ObjectInputStream ois = new PrintUIDs(in); 
    ois.readObject(); 
  } 
 
} 
 

 

I believe it would be possible to read all the serialized data by replacing the descriptor returned by the method, but I haven't tried it.


2)

There is metadata associated with the serialized bits (a header if you like). You can read the value from the metadata if you know at which position it is (the SerialVersionUID is written there along with other info such as the class name).

I think this article might help you: The Java serialization algorithm revealed .

Note that the bits are written "in clear" (unless you encrypted the stream explicitly) so a HEX editor might be all you need to see what is the SerialVersionUID .



This article originates from http://stackoverflow.com/questions/1321988/finding-serialversionuid-of-serialized-object

分享到:
评论

相关推荐

    A Unified Method for Finding Impossible Differentials of

    本文介绍了一种系统化的方法——统一不可能差分查找方法(Unified Impossible Differential finding method, UID-method),用于高效地寻找各种块密码结构中的不可能差分。这种方法相较于先前由Kim等人提出的U-...

    Adaptive Control of Multi-Agent Systems for Finding Peaks of Uncertain Fields

    在所给文件标题中提到的“Adaptive Control of Multi-Agent Systems for Finding Peaks of Uncertain Fields”,指的就是在不确定的环境中,通过自适应控制算法来指导多代理系统协同工作,以寻找某个不确定场的峰值...

    99 Bottles of OOP A Practical Guide to Object-Oriented Design 1st Edition

    99 Bottles of OOP is a practical guide to writing cost-effective, maintainable, and pleasing object-oriented code. It explores: Recognizing when code is “good enough” Getting the best value from ...

    Object-Oriented Software Construction 2nd

    Chapter 2: Criteria of object orientation 21 2.1 ON THE CRITERIA 21 2.2 METHOD AND LANGUAGE 22 2.3 IMPLEMENTATION AND ENVIRONMENT 31 2.4 LIBRARIES 33 2.5 FOR MORE SNEAK PREVIEW 34 2.6 BIBLIOGRAPHICAL ...

    finding experts on link of data

    在探讨“finding experts on link of data”这一主题时,我们深入研究了由Lada Adamic与Eytan Adar撰写的论文摘要,该文详细分析了如何在一个社会网络中搜索和定位专家或特定个体,特别是在仅能利用局部信息的情况下...

    Area-and-Volume-of-a-Circle.rar_The Finding

    Finding the area and volume of a circle on matlab

    edge_finding_matlab边缘寻找_

    "edge_finding_matlab边缘寻找_"这个标题所指的是使用MATLAB进行图像边缘检测的过程。下面我们将深入探讨这一主题。 边缘检测的主要目的是将图像从二维空间转化为一维边缘描述,从而简化图像并突出重要的特征。...

    kuka_SeamTech_Finding中文说明书--视觉探寻.pdf

    SeamTech Finding是库卡系统中一款集成视觉探寻功能的软件,用于工业机器人在进行焊接、装配等任务时,通过视觉系统找到焊接缝隙等特征的位置。接下来,将详细介绍SeamTech Finding软件的主要知识点。 ### 1. ...

    finding a majority among n votes.pdf

    finding a majority among n votes.pdffinding a majority among n votes.pdffinding a majority among n votes.pdffinding a majority among n votes.pdfv

    Handbook of Model Checking

    Satisfiability Modulo Theories (SMT) has contributed to finding excellent ways to pose and solve problems. Uses of temporal logic and data-flow-analysis techniques have also made model checking more ...

    finding_no_of-clusters_in_kmeans.tar.gz_Kmeans

    在给定的“finding_no_of-clusters_in_kmeans.tar.gz_Kmeans”压缩包文件中,我们可以推测其内容可能涉及到确定K-Means聚类算法的最佳簇数量的过程。这个过程通常称为肘部法则(Elbow Method)或轮廓系数法...

    Finding community structure in networks using the eigenvectors of matrices

    本文介绍的标题是“使用矩阵的特征向量寻找网络中的社团结构”,主要围绕着newman算法及其在解决网络社团划分问题中的应用进行阐述。社团划分问题是一个研究网络中具有密集内部连接和稀疏外部连接的顶点组的重要领域...

    信息安全_数据安全_Finding a Domain’s Worth of Malware.pdf

    信息安全_数据安全_Finding a Domain’s Worth of Malware 云数据库 安全防御 区块链 安全防御 安全芯片

    md.rar_angle of arrival_direction finding_md_测向_高分辨

    通过对"md.rar_angle of arrival_direction finding_md_测向_高分辨"这一主题的深入研究,我们可以更全面地理解如何利用先进的数学工具来解决实际的工程问题,提高系统的性能和可靠性。对于"md.txt"文件,它可能是对...

    Continuous Deployment of Mobile Software at Facebook

    We argue that this finding is due to the fact that increasing the frequency of continuous deployment forces improved release and deployment automation, which in turn reduces developer workload....

    Matlab安装Error finding installer class解决方法

    ### Matlab安装Error finding installer class解决方法 #### 问题背景及表现 在安装特定版本的Matlab(例如R2009b、R2010b等)时,可能会遇到一个名为“Error finding installer class”的错误。这个错误通常出现在...

    finding-lungs-in-ct-data.zip

    "finding-lungs-in-ct-data.zip" 文件集合显然与CT图像处理相关,特别是关注肺部的分析。这个压缩包包含了几个关键文件,它们提供了用于肺部分割和体积识别的数据和结果。 首先,`lung_stats.csv` 文件很可能是记录...

Global site tag (gtag.js) - Google Analytics