-
@Documented @Retention(RUNTIME) @Target({FIELD,TYPE}) public @interface Until
An annotation that indicates the version number until a member or a type should be present. Basically, if Gson is created with a version number that exceeds the value stored in theUntilannotation then the field will be ignored from the JSON output. This annotation is useful to manage versioning of your JSON classes for a web-service.This annotation has no effect unless you build
Gsonwith aGsonBuilderand 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; @Until(1.1) private String emailAddress; @Until(1.1) private String password; }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.2).create()then thetoJson()andfromJson()methods of Gson will exclude theemailAddressandpasswordfields from the example above, because the version number passed to the GsonBuilder,1.2, exceeds the version number set on theUntilannotation,1.1, for those fields.- Since:
- 1.3
- Author:
- Inderjeet Singh, Joel Leitch
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description doublevaluethe value indicating a version number until this member or type should be ignored.
-