X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fcom%2Fgoogle%2Fgson%2Fannotations%2FSerializedName.java;fp=src%2Fcom%2Fgoogle%2Fgson%2Fannotations%2FSerializedName.java;h=99755eb5f37a6d2466ece940c17d005dd7d597dc;hb=cfd903b6b5113fa28991db19bf98d0340ae709a4;hp=0000000000000000000000000000000000000000;hpb=819197b2305a94ab4924c5ae37a3fad762078448;p=unical.git diff --git a/src/com/google/gson/annotations/SerializedName.java b/src/com/google/gson/annotations/SerializedName.java new file mode 100644 index 0000000..99755eb --- /dev/null +++ b/src/com/google/gson/annotations/SerializedName.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gson.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * An annotation that indicates this member should be serialized to JSON with + * the provided name value as its field name. + * + *

This annotation will override any {@link com.google.gson.FieldNamingPolicy}, including + * the default field naming policy, that may have been set on the {@link com.google.gson.Gson} + * instance. A different naming policy can set using the {@code GsonBuilder} class. See + * {@link com.google.gson.GsonBuilder#setFieldNamingPolicy(com.google.gson.FieldNamingPolicy)} + * for more information.

+ * + *

Here is an example of how this annotation is meant to be used:

+ *
+ * public class SomeClassWithFields {
+ *   @SerializedName("name") private final String someField;
+ *   private final String someOtherField;
+ *
+ *   public SomeClassWithFields(String a, String b) {
+ *     this.someField = a;
+ *     this.someOtherField = b;
+ *   }
+ * }
+ * 
+ * + *

The following shows the output that is generated when serializing an instance of the + * above example class:

+ *
+ * SomeClassWithFields objectToSerialize = new SomeClassWithFields("a", "b");
+ * Gson gson = new Gson();
+ * String jsonRepresentation = gson.toJson(objectToSerialize);
+ * System.out.println(jsonRepresentation);
+ *
+ * ===== OUTPUT =====
+ * {"name":"a","someOtherField":"b"}
+ * 
+ * + *

NOTE: The value you specify in this annotation must be a valid JSON field name.

+ * + * @see com.google.gson.FieldNamingPolicy + * + * @author Inderjeet Singh + * @author Joel Leitch + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface SerializedName { + + /** + * @return the desired name of the field when it is serialized + */ + String value(); +}