Example usage for com.google.gson JsonElement getAsString

List of usage examples for com.google.gson JsonElement getAsString

Introduction

In this page you can find the example usage for com.google.gson JsonElement getAsString.

Prototype

public String getAsString() 

Source Link

Document

convenience method to get this element as a string value.

Usage

From source file:com.getperka.flatpack.codexes.EnumCodex.java

License:Apache License

@Override
public E readNotNull(JsonElement element, DeserializationContext context) {
    return Enum.valueOf(clazz, element.getAsString());
}

From source file:com.getperka.flatpack.codexes.HasUuidClassCodex.java

License:Apache License

@Override
public Class<? extends HasUuid> readNotNull(JsonElement element, DeserializationContext context)
        throws Exception {
    String name = element.getAsString();
    return typeContext.getClass(name);
}

From source file:com.getperka.flatpack.codexes.StringCodex.java

License:Apache License

@Override
public String readNotNull(JsonElement element, DeserializationContext context) {
    return element.getAsString();
}

From source file:com.getperka.flatpack.codexes.ToStringCodex.java

License:Apache License

@Override
public T readNotNull(JsonElement element, DeserializationContext context) throws Exception {
    return constructor.newInstance(element.getAsString());
}

From source file:com.getperka.flatpack.codexes.TypeHintCodex.java

License:Apache License

@Override
public TypeHint readNotNull(JsonElement element, DeserializationContext context) throws Exception {
    return TypeHint.create(element.getAsString());
}

From source file:com.getperka.flatpack.codexes.UUIDCodex.java

License:Apache License

@Override
public UUID readNotNull(JsonElement element, DeserializationContext context) {
    return UUID.fromString(element.getAsString());
}

From source file:com.github.api.v2.services.impl.BaseGitHubService.java

License:Apache License

/**
 * Gets the gson builder.//from w  ww  .j a va 2s  .  co m
 * 
 * @return the gson builder
 */
protected GsonBuilder getGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat(ApplicationConstants.DATE_FORMAT);
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    builder.setFieldNamingStrategy(new FieldNamingStrategy() {
        @Override
        public String translateName(Field field) {
            if (field.getType().equals(Repository.Visibility.class)) {
                return "private";
            } else if (field.getType().equals(Gist.Visibility.class)) {
                return "public";
            } else {
                return field.getName();
            }
        }

    });
    builder.registerTypeAdapter(Issue.State.class, new JsonDeserializer<Issue.State>() {
        @Override
        public Issue.State deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return Issue.State.fromValue(arg0.getAsString());
        }
    });
    builder.registerTypeAdapter(Repository.Visibility.class, new JsonDeserializer<Repository.Visibility>() {
        @Override
        public Repository.Visibility deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return (arg0.getAsBoolean()) ? Repository.Visibility.PRIVATE : Repository.Visibility.PUBLIC;
        }
    });
    builder.registerTypeAdapter(Gist.Visibility.class, new JsonDeserializer<Gist.Visibility>() {
        @Override
        public Gist.Visibility deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return (arg0.getAsBoolean()) ? Gist.Visibility.PUBLIC : Gist.Visibility.PRIVATE;
        }
    });
    builder.registerTypeAdapter(Language.class, new JsonDeserializer<Language>() {
        @Override
        public Language deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return Language.fromValue(arg0.getAsString());
        }
    });
    builder.registerTypeAdapter(Tree.Type.class, new JsonDeserializer<Tree.Type>() {
        @Override
        public Tree.Type deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return Tree.Type.fromValue(arg0.getAsString());
        }
    });
    return builder;
}

From source file:com.github.autermann.matlab.json.MatlabRequestSerializer.java

License:Open Source License

private MatlabType parseType(JsonElement json) throws JsonParseException {
    String type = json.getAsString();
    try {/*from w w w  . j  av  a2 s .c  om*/
        return MatlabType.fromString(type);
    } catch (IllegalArgumentException e) {
        throw new JsonParseException("Unknown type: " + type);
    }
}

From source file:com.github.autermann.matlab.json.MatlabValueSerializer.java

License:Open Source License

private MatlabString parseMatlabString(JsonElement value) {
    return new MatlabString(value.getAsString());
}

From source file:com.github.autermann.matlab.json.MatlabValueSerializer.java

License:Open Source License

private MatlabFile parseMatlabFile(JsonElement value) {
    return new MatlabFile(gunzip(value.getAsString()));
}