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 Project: azure-mobile-apps-android-client   Author: Azure   File: JsonEntityParser.java    License: 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 #2
Source Project: azure-mobile-apps-android-client   Author: Azure   File: MobileServiceClient.java    License: 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 #3
Source Project: azure-mobile-apps-android-client   Author: Azure   File: MobileServiceTableBase.java    License: 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 #4
Source Project: ProjectAres   Author: OvercastNetwork   File: DocumentRegistry.java    License: 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 #5
Source Project: yandex-money-sdk-java   Author: yandex-money   File: Operation.java    License: 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 #6
Source Project: canvas-api   Author: kstateome   File: CalendarEvent.java    License: 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 #7
Source Project: hmftools   Author: hartwigmedical   File: CivicIndexResult.java    License: GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("_meta")
public abstract CivicApiMetadata meta();
 
Example #8
Source Project: hmftools   Author: hartwigmedical   File: CivicVariantCoordinates.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@SerializedName("reference_build")
public abstract String referenceBuild();
 
Example #9
Source Project: hmftools   Author: hartwigmedical   File: CivicGeneVariantMetadata.java    License: GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("evidence_items")
protected abstract CivicEvidenceItemMetadata evidenceItems();
 
Example #10
Source Project: XiaoxiaZhihu   Author: LiushuiXiaoxia   File: GetThemeResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("image_srouce")
public abstract String getImageSrouce();
 
Example #11
Source Project: android-rxmvp-tutorial   Author: patrick-doyle   File: GitHubRepo.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("url")
public abstract String url();
 
Example #12
Source Project: hmftools   Author: hartwigmedical   File: CivicVariantCoordinates.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@SerializedName("representative_transcript2")
public abstract String representativeTranscript2();
 
Example #13
Source Project: RxUploader   Author: jsaund   File: UserJSONModel.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("id")
public abstract int id();
 
Example #14
Source Project: RxUploader   Author: jsaund   File: UserJSONModel.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("username")
public abstract String username();
 
Example #15
Source Project: XiaoxiaZhihu   Author: LiushuiXiaoxia   File: GetLongCommentsResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("comments")
public abstract List<Comment> getComments();
 
Example #16
Source Project: hmftools   Author: hartwigmedical   File: CivicEvidenceItem.java    License: GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("evidence_level")
public abstract Character level();
 
Example #17
Source Project: RxUploader   Author: jsaund   File: UserJSONModel.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("country")
public abstract String country();
 
Example #18
Source Project: RxUploader   Author: jsaund   File: ImageJSONModel.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("size")
public abstract Integer size();
 
Example #19
Source Project: immutables   Author: immutables   File: NullableArray.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("a")
String[] array();
 
Example #20
Source Project: framework   Author: Odoo-mobile   File: ReflectiveTypeAdapterFactory.java    License: 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 #21
Source Project: hmftools   Author: hartwigmedical   File: LimsJsonSampleData.java    License: GNU General Public License v3.0 4 votes vote down vote up
@NotNull
@SerializedName("ptum")
public abstract String primaryTumor();
 
Example #22
Source Project: XiaoxiaZhihu   Author: LiushuiXiaoxia   File: LastTemeTopStory.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("type")
public abstract int getType();
 
Example #23
Source Project: MOE   Author: google   File: Revision.java    License: 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 #24
Source Project: hmftools   Author: hartwigmedical   File: CivicVariant.java    License: GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("variant_types")
List<CivicVariantType> variantTypes();
 
Example #25
Source Project: XiaoxiaZhihu   Author: LiushuiXiaoxia   File: GetNewsResponse.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("id")
public abstract int getId();
 
Example #26
Source Project: MOE   Author: google   File: Revision.java    License: 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 #27
Source Project: MOE   Author: google   File: EditorConfig.java    License: 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 #28
Source Project: android-rxmvp-tutorial   Author: patrick-doyle   File: GithubUser.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("login")
public abstract String login();
 
Example #29
Source Project: hmftools   Author: hartwigmedical   File: CivicEvidenceItemMetadata.java    License: GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("accepted_count")
public abstract int accepted();
 
Example #30
Source Project: XiaoxiaZhihu   Author: LiushuiXiaoxia   File: Comment.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("id")
public abstract int getId();