-
@Documented @Retention(RUNTIME) @Target({FIELD,TYPE}) public @interface Since
An annotation that indicates the version number since a member or a type has been present. This annotation is useful to manage versioning of your Json classes for a web-service.This annotation has no effect unless you build
Gson
with aGsonBuilder
and invokeGsonBuilder.setVersion(double)
method.Here is an example of how this annotation is meant to be used:
public class User { private String firstName; private String lastName; @Since(1.0) private String emailAddress; @Since(1.0) private String password; @Since(1.1) private Address address; }
If you created Gson with
new Gson()
, thetoJson()
andfromJson()
methods will use all the fields for serialization and deserialization. However, if you created Gson withGson gson = new GsonBuilder().setVersion(1.0).create()
then thetoJson()
andfromJson()
methods of Gson will exclude theaddress
field since it's version number is set to1.1
.- Author:
- Inderjeet Singh, Joel Leitch
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description double
value
the value indicating a version number since this member or type has been present.
-