json文件格式的升级路径 [英] Upgrade path for json file format

查看:108
本文介绍了json文件格式的升级路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 Jackson 将Java应用程序的用户首选项存储在JSON文件中。在我们继续开发应用程序时,我们将添加首选项,重命名首选项以及删除过时的首选项。当用户将应用程序升级到下一版本时,文件格式可能已更改。这导致Jackson抛出异常,即使格式相同,该文件也无法解析。我该如何处理升级文件格式?

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?

我在考虑使用 JSONT 来升级文件以及编写我自己的Jackson流解析器,它比完全绑定解析器更宽松,以防万一JSONT升级出现问题。其他人如何处理升级文件格式?

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目前没有任何内置的JSON版本支持,例如 Gson确实。两年前,杰克逊问题108 被记录下来,以解决这种可能的增强问题。请毫不犹豫地投票支持其实施。 (我刚刚做过。)

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.)

我将采用的方法是实现自定义JSON版本控制解决方案,类似于Gson的工作方式。 (单独使用这一功能可能不足以让我切换到Gson。)然后,在反序列化后或自定义反序列化期间处理不同版本时,Java bean处理中的逻辑可能相对简单。

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.

这篇关于json文件格式的升级路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆