Example usage for com.google.gson JsonDeserializationContext deserialize

List of usage examples for com.google.gson JsonDeserializationContext deserialize

Introduction

In this page you can find the example usage for com.google.gson JsonDeserializationContext deserialize.

Prototype

public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;

Source Link

Document

Invokes default deserialization on the specified object.

Usage

From source file:com.arangodb.entity.EntityDeserializers.java

License:Apache License

private static VertexEntity<Object> getVertex(JsonDeserializationContext context, JsonObject vertex,
        Class<?> vertexClazz) {
    VertexEntity<Object> ve = deserializeBaseParameter(vertex, new VertexEntity<Object>());
    deserializeDocumentParameter(vertex, ve);
    if (vertexClazz != null) {
        ve.setEntity(context.deserialize(vertex, vertexClazz));
    } else {/*from  ww  w  .  j ava  2s  .  c om*/
        ve.setEntity(context.deserialize(vertex, Object.class));
    }
    return ve;
}

From source file:com.arangodb.entity.EntityDeserializers.java

License:Apache License

private static List<EdgeEntity<Object>> getEdges(Class<?> edgeClazz, JsonDeserializationContext context,
        JsonArray edges) {//from   www . ja va2s .com
    List<EdgeEntity<Object>> list = new ArrayList<EdgeEntity<Object>>();
    if (!edges.equals(null)) {
        for (int i = 0, imax = edges.size(); i < imax; i++) {
            JsonObject edge = edges.get(i).getAsJsonObject();
            EdgeEntity<Object> ve = deserializeBaseParameter(edge, new EdgeEntity<Object>());
            deserializeDocumentParameter(edge, ve);
            if (edgeClazz != null) {
                ve.setEntity(context.deserialize(edge, edgeClazz));
            } else {
                ve.setEntity(context.deserialize(edge, Object.class));
            }
            list.add(ve);
        }
    }
    return list;
}

From source file:com.arcbees.vcs.github.util.GitHubPullRequestsTypeAdapter.java

License:Apache License

@Override
public GitHubPullRequests deserialize(JsonElement json, Type typeOfT, final JsonDeserializationContext context)
        throws JsonParseException {
    JsonArray jsonArray = json.getAsJsonArray();

    List<GitHubPullRequest> pullRequests = FluentIterable.from(jsonArray)
            .transform(new Function<JsonElement, GitHubPullRequest>() {
                @Override//from w  w  w. j av a  2 s . co  m
                public GitHubPullRequest apply(JsonElement input) {
                    return context.deserialize(input, GitHubPullRequest.class);
                }
            }).toImmutableList();

    GitHubPullRequests gitHubPullRequests = new GitHubPullRequests();
    gitHubPullRequests.setPullRequests(pullRequests);

    return gitHubPullRequests;
}

From source file:com.arcbees.vcs.util.PolymorphicTypeAdapter.java

License:Apache License

@Override
public T deserialize(JsonElement json, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(CLASSNAME);
    String className = jsonPrimitive.getAsString();

    Class<?> clazz;/*from ww  w  .j  a va  2 s. com*/
    try {
        clazz = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new JsonParseException(e.getMessage());
    }

    return context.deserialize(jsonObject.get(VALUE), clazz);
}

From source file:com.asakusafw.lang.inspection.json.NodeAdapter.java

License:Apache License

@Override
public InspectionNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject() == false) {
        throw new JsonParseException("node must be an object"); //$NON-NLS-1$
    }/*w  w  w .ja  va2s.c  om*/
    JsonObject object = (JsonObject) json;
    String id = object.get(KEY_ID).getAsString();
    String title = object.get(KEY_TITLE).getAsString();
    List<Port> inputs = context.deserialize(object.get(KEY_INPUTS), TYPE_PORTS);
    List<Port> outputs = context.deserialize(object.get(KEY_OUTPUTS), TYPE_PORTS);
    Map<String, String> properties = context.deserialize(object.get(KEY_PROPERTIES), TYPE_PROPERTIES);
    List<InspectionNode> elements = context.deserialize(object.get(KEY_ELEMENTS), TYPE_NODES);

    InspectionNode result = new InspectionNode(id, title);
    put(inputs, result.getInputs());
    put(outputs, result.getOutputs());
    result.getProperties().putAll(properties);
    put(elements, result.getElements());
    return result;
}

From source file:com.asakusafw.lang.inspection.json.PortAdapter.java

License:Apache License

@Override
public InspectionNode.Port deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject() == false) {
        throw new JsonParseException("port must be an object"); //$NON-NLS-1$
    }/*  www.j a  va  2s. c  om*/
    JsonObject object = (JsonObject) json;
    String id = object.get(KEY_ID).getAsString();
    Map<String, String> properties = context.deserialize(object.get(KEY_PROPERTIES), TYPE_PROPERTIES);
    Set<PortReference> opposites = context.deserialize(object.get(KEY_OPPOSITES), TYPE_REFERENCES);

    InspectionNode.Port result = new InspectionNode.Port(id);
    result.getProperties().putAll(properties);
    result.getOpposites().addAll(opposites);
    return result;
}

From source file:com.auth0.android.lock.internal.configuration.ApplicationDeserializer.java

License:Open Source License

private List<Connection> parseStrategy(JsonElement json, JsonDeserializationContext context) {
    final JsonObject strategy = json.getAsJsonObject();
    String name = requiredValue("name", String.class, strategy, context);
    requiredValue("connections", Object.class, strategy, context);

    JsonArray connectionsArray = strategy.getAsJsonArray("connections");
    List<Connection> connections = new ArrayList<>();
    for (int i = 0; i < connectionsArray.size(); i++) {
        final JsonObject connectionJson = connectionsArray.get(i).getAsJsonObject();
        requiredValue("name", String.class, connectionJson, context);
        Type mapType = new TypeToken<LinkedTreeMap<String, Object>>() {
        }.getType();/*from  ww w .j a  va  2  s  .  co  m*/
        Map<String, Object> values = context.deserialize(connectionJson, mapType);
        connections.add(Connection.newConnectionFor(name, values));
    }
    return connections;
}

From source file:com.auth0.android.lock.internal.configuration.GsonDeserializer.java

License:Open Source License

<U> U requiredValue(String name, Type type, JsonObject object, JsonDeserializationContext context)
        throws JsonParseException {
    U value = context.deserialize(object.get(name), type);
    if (value == null) {
        throw new JsonParseException(String.format("Missing required attribute %s", name));
    }//from ww w . java  2  s  . co  m
    return value;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.CubeDeserialize.java

License:Open Source License

@Override
public Cube deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        MiniCube cube = context.deserialize(json, MiniCube.class);
        return cube;
    }//from  w  w  w . ja va 2 s .c o m
    return null;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.DataSourceInfoDeserialize.java

License:Open Source License

@Override
public DataSourceInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        DataSourceType dataSourceType = context.deserialize(json.getAsJsonObject().get("dataSourceType"),
                DataSourceType.class);
        if (dataSourceType.equals(DataSourceType.SQL)) {
            return context.deserialize(json, SqlDataSourceInfo.class);
        }/*w ww  .  j av  a 2  s  . c  o m*/

    }
    return null;
}