Top Description Methods
com.google.gson.annotations

public @Interface Since

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:FIELD, TYPE
Imports
com.google.gson.GsonBuilder, java.lang.annotation.Documented, .ElementType, .Retention, .RetentionPolicy, .Target

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 com.google.gson.Gson with a GsonBuilder and invoke the GsonBuilder#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(), the toJson() and fromJson() methods will use all the fields for serialization and deserialization. However, if you created Gson with Gson gson = new GsonBuilder().setVersion(1.0).create() then the toJson() and fromJson() methods of Gson will exclude the address field since it's version number is set to 1.1.

Authors
Inderjeet Singh, Joel Leitch
See Also
GsonBuilder#setVersion(double), Until

Method Summary

Modifier and TypeMethod and Description
public double
value()

The value indicating a version number since this member or type has been present.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public double value()

The value indicating a version number since this member or type has been present. The number is inclusive; annotated elements will be included if gsonVersion >= value.