• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.gson.annotations;
18 
19 import com.google.gson.GsonBuilder;
20 import java.lang.annotation.Documented;
21 import java.lang.annotation.ElementType;
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 import java.lang.annotation.Target;
25 
26 /**
27  * An annotation that indicates the version number since a member or a type has been present.
28  * This annotation is useful to manage versioning of your JSON classes for a web-service.
29  *
30  * <p>
31  * This annotation has no effect unless you build {@link com.google.gson.Gson} with a
32  * {@code GsonBuilder} and invoke the {@link GsonBuilder#setVersion(double)} method.
33  *
34  * <p>Here is an example of how this annotation is meant to be used:</p>
35  * <pre>
36  * public class User {
37  *   private String firstName;
38  *   private String lastName;
39  *   &#64;Since(1.0) private String emailAddress;
40  *   &#64;Since(1.0) private String password;
41  *   &#64;Since(1.1) private Address address;
42  * }
43  * </pre>
44  *
45  * <p>If you created Gson with {@code new Gson()}, the {@code toJson()} and {@code fromJson()}
46  * methods will use all the fields for serialization and deserialization. However, if you created
47  * Gson with {@code Gson gson = new GsonBuilder().setVersion(1.0).create()} then the
48  * {@code toJson()} and {@code fromJson()} methods of Gson will exclude the {@code address} field
49  * since it's version number is set to {@code 1.1}.</p>
50  *
51  * @author Inderjeet Singh
52  * @author Joel Leitch
53  * @see GsonBuilder#setVersion(double)
54  * @see Until
55  */
56 @Documented
57 @Retention(RetentionPolicy.RUNTIME)
58 @Target({ElementType.FIELD, ElementType.TYPE})
59 public @interface Since {
60   /**
61    * The value indicating a version number since this member or type has been present.
62    * The number is inclusive; annotated elements will be included if {@code gsonVersion >= value}.
63    */
value()64   double value();
65 }
66