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

283 Views Asked by At

I use Protostuff RuntimeSchema in the most basic way :

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

I will save the result byte[] somewhere and deserialize it in the future.

But there is a chance that I will add some fields in Bean.class (and also generate a new schema).

I tested some times, it works fine, i can get the new fields as 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.

1

There are 1 best solutions below

0
On BEST ANSWER

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.

However, things might get a little bit tricky if you use inheritance. In this case you should consider using @Tag annotation.