]>
iEval git - unical.git/blob - gson/com/google/gson/annotations/SerializedName.java
2 * Copyright (C) 2008 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com
.google
.gson
.annotations
;
19 import java
.lang
.annotation
.ElementType
;
20 import java
.lang
.annotation
.Retention
;
21 import java
.lang
.annotation
.RetentionPolicy
;
22 import java
.lang
.annotation
.Target
;
25 * An annotation that indicates this member should be serialized to JSON with
26 * the provided name value as its field name.
28 * <p>This annotation will override any {@link com.google.gson.FieldNamingPolicy}, including
29 * the default field naming policy, that may have been set on the {@link com.google.gson.Gson}
30 * instance. A different naming policy can set using the {@code GsonBuilder} class. See
31 * {@link com.google.gson.GsonBuilder#setFieldNamingPolicy(com.google.gson.FieldNamingPolicy)}
32 * for more information.</p>
34 * <p>Here is an example of how this annotation is meant to be used:</p>
36 * public class SomeClassWithFields {
37 * @SerializedName("name") private final String someField;
38 * private final String someOtherField;
40 * public SomeClassWithFields(String a, String b) {
42 * this.someOtherField = b;
47 * <p>The following shows the output that is generated when serializing an instance of the
48 * above example class:</p>
50 * SomeClassWithFields objectToSerialize = new SomeClassWithFields("a", "b");
51 * Gson gson = new Gson();
52 * String jsonRepresentation = gson.toJson(objectToSerialize);
53 * System.out.println(jsonRepresentation);
56 * {"name":"a","someOtherField":"b"}
59 * <p>NOTE: The value you specify in this annotation must be a valid JSON field name.</p>
61 * @see com.google.gson.FieldNamingPolicy
63 * @author Inderjeet Singh
66 @Retention(RetentionPolicy
.RUNTIME
)
67 @Target(ElementType
.FIELD
)
68 public @interface SerializedName
{
71 * @return the desired name of the field when it is serialized
This page took 0.043848 seconds and 4 git commands to generate.