Annotation Type SerializedName

public @interface SerializedName

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 FieldNamingPolicy, including the default field naming policy, that may have been set on the Gson instance. A different naming policy can set using the GsonBuilder class. See GsonBuilder.setFieldNamingPolicy( 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);

 ===== OUTPUT =====

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

Inderjeet Singh, Joel Leitch
See Also:

Required Element Summary
 String value

Element Detail


public abstract String value
the desired name of the field when it is serialized

Copyright © 2008-2010. All Rights Reserved.