Search code examples
javagoogle-app-engineobjectify

From serialized list field to list field objectify


I'm using objectify on my GAE java server and I want to update a class entity with a field which was a list with the @Serialize annotation and I want now to transform it to a simple list.

How can I do that?


Solution

  • Basically you create a second field that holds your preferred format and use an @OnLoad method to migrate the data. Then load/save all entities.

    However, there's a catch. If you have a busy system, you can be assured that the old version and the new version will coexist for some number of requests. So you have to be somewhat careful about the transition. The safest way is to:

    1. Deploy code that creates (and preserves) the new field, preferentially using it, but don't write data to it.
    2. Deploy code that migrates the data in the @OnLoad, dropping the old data with @IgnoreSave(IfNull.class) (or however you prefer)
    3. Reprocess all entities via load + save
    4. Drop the old field from you code