简体   繁体   English

使用Protostuff默认的RuntimeSchema时,在java类末尾添加字段总是安全的吗?

[英]Is adding fields at the end of a java class always safe when using Protostuff default RuntimeSchema?

I use Protostuff RuntimeSchema in the most basic way : 我以最基本的方式使用Protostuff RuntimeSchema:

Schema<Bean> schema = RuntimeSchema.createFrom(Bean.class);

I will save the result byte[] somewhere and deserialize it in the future. 我会在某处保存结果byte [],并在将来反序列化它。

But there is a chance that I will add some fields in Bean.class (and also generate a new schema). 但是我有可能在Bean.class中添加一些字段(并且还生成一个新的模式)。

I tested some times, it works fine, i can get the new fields as null. 我测试了一些,它工作正常,我可以将新字段作为null。

But I want to make sure if it is always safe, assuming that new fields are always added in the end of Bean, and always use HotSpot JDK. 但是我想确保它是否总是安全的,假设新字段总是在Bean的末尾添加,并且总是使用HotSpot JDK。

Yes, if you append field to the end of the fields list, it is safe. 是的,如果将字段追加到字段列表的末尾,则是安全的。 RuntimeSchema assigns tags to fields according to their order in the class. RuntimeSchema根据字段中的顺序为字段分配标记。

However, things might get a little bit tricky if you use inheritance. 但是,如果使用继承,事情可能会有点棘手。 In this case you should consider using @Tag annotation. 在这种情况下,您应该考虑使用@Tag注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM