Java Code Examples for com.google.gson.annotations.SerializedName

The following examples show how to use com.google.gson.annotations.SerializedName. These examples are extracted from open source projects. 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
/**
 * 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
/**
 * 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
/**
 * @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
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   Source 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
@SerializedName("daily")
DAILY,
@SerializedName("weekly")
WEEKLY,
@SerializedName("monthly")
MONTHLY;

@Override
public String toString() { return name().toLowerCase(); }
 
Example 7
Source Project: hmftools   Source File: CivicIndexResult.java    License: GNU General Public License v3.0 4 votes vote down vote up
@SerializedName("_meta")
public abstract CivicApiMetadata meta();
 
Example 8
@Nullable
@SerializedName("reference_build")
public abstract String referenceBuild();
 
Example 9
@SerializedName("evidence_items")
protected abstract CivicEvidenceItemMetadata evidenceItems();
 
Example 10
Source Project: XiaoxiaZhihu   Source 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   Source File: GitHubRepo.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("url")
public abstract String url();
 
Example 12
@Nullable
@SerializedName("representative_transcript2")
public abstract String representativeTranscript2();
 
Example 13
Source Project: RxUploader   Source 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   Source 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   Source 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   Source 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   Source 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   Source 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   Source File: NullableArray.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@SerializedName("a")
String[] array();
 
Example 20
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   Source 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   Source 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   Source 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   Source 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   Source 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   Source 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   Source 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   Source File: GithubUser.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("login")
public abstract String login();
 
Example 29
@SerializedName("accepted_count")
public abstract int accepted();
 
Example 30
Source Project: XiaoxiaZhihu   Source File: Comment.java    License: Apache License 2.0 4 votes vote down vote up
@SerializedName("id")
public abstract int getId();