java Google GSON:如何使用@Since注释,例如版本“1.2.1”?(无效双精度)
我正在Java应用程序中使用Google GSON
设想以下情况:在版本1.2.1
中添加了一个新的JSON属性。我如何在^{@Since(1.2.1)
是不可能的,因为1.2.1
不是有效的双精度。我的版本格式是<major>.<minor>.<patch>
我注意到的另一件事是,如果我有版本1.20
,GSON将其视为比例如版本1.3
更低的版本
有什么办法解决这个问题吗?也许可以做一些像定制排他性的工作?(这是否存在?)
除了版本问题之外,我注意到^{
# 1 楼答案
看起来
@Since
注释有点有限,不适合您。您需要自定义排除策略是正确的。下面这样的方法会奏效:为要使用的版本创建自己的注释,而不是
@Since
:自定义排除策略:
versionCompare
方法是比较版本字符串的方法。我使用了这个问题答案中的一个:How do you compare two version Strings in Java?用法:
我不确定这对课堂有什么用处。可以对类进行注释,这样就不必对其他类中的所有类引用进行注释,但仅此而已