com.google.gson.annotations.SerializedName Java Examples

The following examples show how to use com.google.gson.annotations.SerializedName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MobileServiceTableBase.java    From azure-mobile-apps-android-client with Apache License 2.0 6 votes vote down vote up
/**
 * @return the system properties defined or annotated in the entity class
 *
 * @param clazz Target entity class
 */
public static <F> EnumSet<MobileServiceSystemProperty> getSystemProperties(Class<F> clazz) {
    EnumSet<MobileServiceSystemProperty> result = EnumSet.noneOf(MobileServiceSystemProperty.class);

    Class<?> idClazz = getIdPropertyClass(clazz);

    if (idClazz != null && !isIntegerClass(idClazz)) {
        // Search for system properties annotations, regardless case
        for (Field field : clazz.getDeclaredFields()) {
            SerializedName serializedName = field.getAnnotation(SerializedName.class);

            if (serializedName != null) {
                if (SystemPropertyNameToEnum.containsKey(serializedName.value())) {
                    result.add(SystemPropertyNameToEnum.get(serializedName.value()));
                }
            } else {
                if (SystemPropertyNameToEnum.containsKey(field.getName())) {
                    result.add(SystemPropertyNameToEnum.get(field.getName()));
                }
            }
        }
    }

    // Otherwise, return empty
    return result;
}
 
Example #2
Source File: JsonEntityParser.java    From azure-mobile-apps-android-client with Apache License 2.0 6 votes vote down vote up
/**
 * Get's the class' id property name
 *
 * @param clazz
 * @return Id Property name
 */
@SuppressWarnings("rawtypes")
private static String getIdPropertyName(Class clazz) {
    // Search for annotation called id, regardless case
    for (Field field : clazz.getDeclaredFields()) {

        SerializedName serializedName = field.getAnnotation(SerializedName.class);
        if (serializedName != null && serializedName.value().equalsIgnoreCase("id")) {
            return serializedName.value();
        } else if (field.getName().equalsIgnoreCase("id")) {
            return field.getName();
        }
    }

    // Otherwise, return empty
    return "";
}
 
Example #3
Source File: MobileServiceClient.java    From azure-mobile-apps-android-client with Apache License 2.0 6 votes vote down vote up
/**
 * Validates the class has an id property defined
 *
 * @param clazz
 */
private <E> void validateClass(Class<E> clazz) {
    if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
        throw new IllegalArgumentException("The class type used for creating a MobileServiceTable must be a concrete class");
    }

    int idPropertyCount = 0;
    for (Field field : clazz.getDeclaredFields()) {
        SerializedName serializedName = field.getAnnotation(SerializedName.class);
        if (serializedName != null) {
            if (serializedName.value().equalsIgnoreCase("id")) {
                idPropertyCount++;
            }
        } else {
            if (field.getName().equalsIgnoreCase("id")) {
                idPropertyCount++;
            }
        }
    }

    if (idPropertyCount != 1) {
        throw new IllegalArgumentException("The class representing the MobileServiceTable must have a single id property defined");
    }
}
 
Example #4
Source File: CalendarEvent.java    From canvas-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SerializedName("daily")
DAILY,
@SerializedName("weekly")
WEEKLY,
@SerializedName("monthly")
MONTHLY;

@Override
public String toString() { return name().toLowerCase(); }
 
Example #5
Source File: DocumentRegistry.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private static String serializedName(Member member) {
    if(member instanceof AnnotatedElement) {
        SerializedName nameAnnot = ((AnnotatedElement) member).getAnnotation(SerializedName.class);
        if(nameAnnot != null) return nameAnnot.value();
    }
    return member.getName();
}
 
Example #6
Source File: Operation.java    From yandex-money-sdk-java with MIT License 5 votes vote down vote up
@SerializedName("turn-on-reminder")
TURN_ON_REMINDER("turn-on-reminder"),
@SerializedName("turn-on-autopayment")
TURN_ON_AUTOPAYMENT("turn-on-autopayment"),
@SerializedName("repeat")
REPEAT("repeat"),
@SerializedName("add-to-favourites")
ADD_TO_FAVOURITES("add-to-favourites");
 
Example #7
Source File: NullableArray.java    From immutables with Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("a")
String[] array();
 
Example #8
Source File: CivicVariant.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("variant_types")
List<CivicVariantType> variantTypes();
 
Example #9
Source File: CivicIndexResult.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("_meta")
public abstract CivicApiMetadata meta();
 
Example #10
Source File: LastTemeTopStory.java    From XiaoxiaZhihu with Apache License 2.0 4 votes vote down vote up
@SerializedName("type")
public abstract int getType();
 
Example #11
Source File: LimsJsonSampleData.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
@NotNull
@SerializedName("ptum")
public abstract String primaryTumor();
 
Example #12
Source File: ReflectiveTypeAdapterFactory.java    From framework with GNU Affero General Public License v3.0 4 votes vote down vote up
static String getFieldName(FieldNamingStrategy fieldNamingPolicy, Field f) {
  SerializedName serializedName = f.getAnnotation(SerializedName.class);
  return serializedName == null ? fieldNamingPolicy.translateName(f) : serializedName.value();
}
 
Example #13
Source File: EditorConfig.java    From MOE with Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("command_string") // TODO(cushon): remove pending rharter/auto-value-gson#18
public abstract String commandString();
 
Example #14
Source File: ImageJSONModel.java    From RxUploader with Apache License 2.0 4 votes vote down vote up
@SerializedName("size")
public abstract Integer size();
 
Example #15
Source File: GetLongCommentsResponse.java    From XiaoxiaZhihu with Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("comments")
public abstract List<Comment> getComments();
 
Example #16
Source File: UserJSONModel.java    From RxUploader with Apache License 2.0 4 votes vote down vote up
@SerializedName("username")
public abstract String username();
 
Example #17
Source File: UserJSONModel.java    From RxUploader with Apache License 2.0 4 votes vote down vote up
@SerializedName("id")
public abstract int id();
 
Example #18
Source File: GetNewsResponse.java    From XiaoxiaZhihu with Apache License 2.0 4 votes vote down vote up
@SerializedName("id")
public abstract int getId();
 
Example #19
Source File: Revision.java    From MOE with Apache License 2.0 4 votes vote down vote up
/** The unique ID assigned to this revision by the underlying revision control system. */
@SerializedName(
  value = "rev_id",
  alternate = {"revId"}
)
public abstract String revId();
 
Example #20
Source File: Revision.java    From MOE with Apache License 2.0 4 votes vote down vote up
/** The label for the configured repository from which this revision originates. */
@SerializedName(
  value = "repository_name",
  alternate = {"repositoryName"}
)
public abstract String repositoryName();
 
Example #21
Source File: GithubUser.java    From android-rxmvp-tutorial with Apache License 2.0 4 votes vote down vote up
@SerializedName("login")
public abstract String login();
 
Example #22
Source File: CivicEvidenceItemMetadata.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("accepted_count")
public abstract int accepted();
 
Example #23
Source File: Comment.java    From XiaoxiaZhihu with Apache License 2.0 4 votes vote down vote up
@SerializedName("id")
public abstract int getId();
 
Example #24
Source File: GithubUser.java    From android-rxmvp-tutorial with Apache License 2.0 4 votes vote down vote up
@SerializedName("name")
public abstract String name();
 
Example #25
Source File: EntityTypeResponseData.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
@CopyAnnotations
@SerializedName(value = "abstract")
public abstract boolean isAbstract();
 
Example #26
Source File: GithubUser.java    From android-rxmvp-tutorial with Apache License 2.0 4 votes vote down vote up
@SerializedName("bio")
public abstract String bio();
 
Example #27
Source File: GithubAPI.java    From MOE with Apache License 2.0 4 votes vote down vote up
@SerializedName("clone_url") // TODO(cushon): remove pending rharter/auto-value-gson#18
public abstract String cloneUrl();
 
Example #28
Source File: LimsJsonSampleData.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("shallowseq")
public abstract boolean shallowSeq();
 
Example #29
Source File: GetThemeResponse.java    From XiaoxiaZhihu with Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("stories")
public abstract List<LastThemeStory> getStories();
 
Example #30
Source File: ThemeItem.java    From XiaoxiaZhihu with Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("thumbnail")
public abstract String getThumbnail();