Example usage for com.google.gson JsonPrimitive getAsInt

List of usage examples for com.google.gson JsonPrimitive getAsInt

Introduction

In this page you can find the example usage for com.google.gson JsonPrimitive getAsInt.

Prototype

@Override
public int getAsInt() 

Source Link

Document

convenience method to get this element as a primitive integer.

Usage

From source file:tk.breezy64.pantex.core.ConfigManager.java

private static Object jsonElementToObject(JsonElement e) {
    if (e.isJsonObject()) {
        return jsonObjectToMap(e.getAsJsonObject());
    } else if (e.isJsonPrimitive()) {
        JsonPrimitive p = e.getAsJsonPrimitive();
        if (p.isNumber()) {
            return p.getAsInt();
        } else if (p.isString()) {
            return p.getAsString();
        } else if (p.isBoolean()) {
            return p.getAsBoolean();
        }//from ww w  . java2  s.c o m
    } else if (e.isJsonArray()) {
        List<Object> list = new ArrayList<>();
        e.getAsJsonArray().forEach((x) -> list.add(jsonElementToObject(x)));
        return list;
    }
    return null;
}