We are storing user preferences for a Java app in a JSON file using Jackson. As we continue to develop the app, we will be adding preferences, renaming preferences, and removing obsolete preferences. When the user upgrades the app to the next version the file format will likely have changed. This causes Jackson to throw an exception and the file can’t be parsed even though the format is 90% the same. How should I handle upgrading the file format?
I was thinking about using JSONT to upgrade the file as well as writing my own Jackson stream parser which is more lenient than the full binding parser, just in case something goes wrong with the JSONT upgrade. What have other people done to handle upgrading file formats?
Jackson doesn’t currently have any built-in JSON versioning support, like Gson does. Jackson issue 108 was logged over two years ago to address such a possible enhancement. Please don’t hesitate to vote for its implementation. (I just did.)
The approach I would take would be to implement a custom JSON versioning support solution, similar to how Gson does it. (This one feature alone probably wouldn’t be enough for me to switch to Gson.) Then logic in your Java bean processing could be relatively straightforward regarding handling different versions either post-deserialization, or during custom deserialization.