gpt4 book ai didi

java - jms 和不同版本的枚举

转载 作者:行者123 更新时间:2023-11-30 05:57:13 25 4
gpt4 key购买 nike

我的团队通过 jms 为公司的另一个团队提供服务。这涉及一个作为更大对象的一部分传递给我们的枚举。他们很快就会改变枚举的定义——但是,我想先改变它,这样我就可以在改变前几天让我们的服务在生产中运行。更改仅涉及在末尾添加另一个常量。我可以安全地执行此操作吗?

最佳答案

来自 Java Object Serialization Specification version 6.0 (强调是我的):

The serialized form of an enum constant consists solely of its name; [...]. To serialize an enum constant, ObjectOutputStream writes the value returned by the enum constant's name method. To deserialize an enum constant, ObjectInputStream reads the constant name from the stream; the deserialized constant is then obtained by calling the java.lang.Enum.valueOf method, passing the constant's enum type along with the received constant name as arguments.

这意味着:

  • enum 添加新值在序列化方面向后兼容
  • 重新排序现有 enum向后兼容(与使用 enum 的默认 JPA ordinal() 持久性策略相反)
  • enum 中删除值一般不向后兼容,因为删除的值可能已用于序列化目的
  • 重命名 enum向后兼容(见上文)

关于java - jms 和不同版本的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6116687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com