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:org.apache.twill.internal.json.ResourceSpecificationCodec.java

License:Apache License

@Override
public ResourceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    final List<String> hosts = context.deserialize(jsonObj.getAsJsonArray("hosts"), List.class);
    final List<String> racks = context.deserialize(jsonObj.getAsJsonArray("racks"), List.class);
    return new DefaultResourceSpecification(jsonObj.get("cores").getAsInt(),
            jsonObj.get("memorySize").getAsInt(), jsonObj.get("instances").getAsInt(),
            jsonObj.get("uplink").getAsInt(), jsonObj.get("downlink").getAsInt());
}

From source file:org.apache.twill.internal.json.RuntimeSpecificationCodec.java

License:Apache License

@Override
public RuntimeSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();

    String name = jsonObj.get("name").getAsString();
    TwillRunnableSpecification runnable = context.deserialize(jsonObj.get("runnable"),
            TwillRunnableSpecification.class);
    ResourceSpecification resources = context.deserialize(jsonObj.get("resources"),
            ResourceSpecification.class);
    Collection<LocalFile> files = context.deserialize(jsonObj.get("files"),
            new TypeToken<Collection<LocalFile>>() {
            }.getType());/*from   w  w w . j  a v a 2 s.com*/

    return new DefaultRuntimeSpecification(name, runnable, resources, files);
}

From source file:org.apache.twill.internal.json.TwillRunnableSpecificationCodec.java

License:Apache License

@Override
public TwillRunnableSpecification deserialize(JsonElement json, Type typeOfT,
        JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();

    String className = jsonObj.get("classname").getAsString();
    String name = jsonObj.get("name").getAsString();
    Map<String, String> arguments = context.deserialize(jsonObj.get("arguments"),
            new TypeToken<Map<String, String>>() {
            }.getType());/*w ww. ja v  a2  s . c o  m*/

    return new DefaultTwillRunnableSpecification(className, name, arguments);
}

From source file:org.apache.twill.internal.json.TwillRuntimeSpecificationCodec.java

License:Apache License

@Override
public TwillRuntimeSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();

    TwillSpecification twillSpecification = context.deserialize(jsonObj.get(TWILL_SPEC),
            new TypeToken<TwillSpecification>() {
            }.getType());//from  w  ww .  j  ava2 s. c  o m
    Map<String, Map<String, String>> logLevels = context.deserialize(jsonObj.get(LOG_LEVELS),
            new TypeToken<Map<String, Map<String, String>>>() {
            }.getType());
    Map<String, Integer> maxRetries = context.deserialize(jsonObj.get(MAX_RETRIES),
            new TypeToken<Map<String, Integer>>() {
            }.getType());

    return new TwillRuntimeSpecification(twillSpecification, jsonObj.get(FS_USER).getAsString(),
            URI.create(jsonObj.get(TWILL_APP_DIR).getAsString()), jsonObj.get(ZK_CONNECT_STR).getAsString(),
            RunIds.fromString(jsonObj.get(TWILL_RUNID).getAsString()),
            jsonObj.get(TWILL_APP_NAME).getAsString(), jsonObj.get(RESERVED_MEMORY).getAsInt(),
            jsonObj.has(RM_SCHEDULER_ADDR) ? jsonObj.get(RM_SCHEDULER_ADDR).getAsString() : null, logLevels,
            maxRetries, jsonObj.get(HEAP_RESERVED_MIN_RATIO).getAsDouble(),
            jsonObj.get(LOG_COLLECTION_ENABLED).getAsBoolean());
}

From source file:org.apache.twill.internal.json.TwillSpecificationCodec.java

License:Apache License

@Override
public TwillSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();

    String name = jsonObj.get("name").getAsString();
    Map<String, RuntimeSpecification> runnables = context.deserialize(jsonObj.get("runnables"),
            new TypeToken<Map<String, RuntimeSpecification>>() {
            }.getType());// ww w . j  a v  a 2s . c om
    List<TwillSpecification.Order> orders = context.deserialize(jsonObj.get("orders"),
            new TypeToken<List<TwillSpecification.Order>>() {
            }.getType());
    List<TwillSpecification.PlacementPolicy> placementPolicies = context.deserialize(
            jsonObj.get("placementPolicies"), new TypeToken<List<TwillSpecification.PlacementPolicy>>() {
            }.getType());

    JsonElement handler = jsonObj.get("handler");
    EventHandlerSpecification eventHandler = null;
    if (handler != null && !handler.isJsonNull()) {
        eventHandler = context.deserialize(handler, EventHandlerSpecification.class);
    }

    return new DefaultTwillSpecification(name, runnables, orders, placementPolicies, eventHandler);
}

From source file:org.catrobat.catroid.io.BackpackBrickSerializerAndDeserializer.java

License:Open Source License

@Override
public Brick deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
    JsonObject jsonObject = json.getAsJsonObject();
    String type = jsonObject.get(TYPE).getAsString();
    JsonElement element = jsonObject.get(PROPERTY);

    Class classToDeserialize;/*from www.j  a  v a 2 s. c o m*/
    try {
        classToDeserialize = Class.forName(type);
    } catch (ClassNotFoundException classNotFoundException) {
        Log.e(TAG, "Could not deserialize backpacked brick element: " + type);
        StorageHandler.getInstance().deleteBackpackFile();
        return null;
    }
    return context.deserialize(element, classToDeserialize);
}

From source file:org.catrobat.catroid.io.BackpackScriptSerializerAndDeserializer.java

License:Open Source License

@Override
public Script deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    JsonObject jsonObject = json.getAsJsonObject();
    String type = jsonObject.get(TYPE).getAsString();
    JsonElement element = jsonObject.get(PROPERTY);

    try {//  ww  w.  j  a  v  a 2  s .c o  m
        return context.deserialize(element, Class.forName(PACKAGE_NAME + type));
    } catch (ClassNotFoundException e) {
        Log.e(TAG, "Could not deserialize backpacked script element!");
        throw new JsonParseException("Unknown element type: " + type, e);
    }
}

From source file:org.cmg.jresp.json.AddressDeserializer.java

License:Open Source License

private Address doDeserialize(String addressCode, JsonObject json, JsonDeserializationContext context) {
    if (addressCode == null) {
        throw new IllegalStateException("This is not an Address!");
    }/*from   ww w.  j ava 2s  .  c  om*/
    if (addressCode.equals(SocketPortAddress.ADDRESS_CODE)) {
        return new SocketPortAddress(
                new InetSocketAddress(json.get("host").getAsString(), json.get("port").getAsInt()));
    }
    if (addressCode.equals(ServerPortAddress.ADDRESS_CODE)) {
        return new ServerPortAddress(
                new InetSocketAddress(json.get("host").getAsString(), json.get("port").getAsInt()));
    }
    if (addressCode.equals(VirtualPortAddress.ADDRESS_CODE)) {
        return new VirtualPortAddress((Integer) context.deserialize(json.get("id"), Integer.class));
    }
    throw new IllegalStateException("This is not an Address!");
}

From source file:org.cmg.jresp.json.GroupPredicateDeserializer.java

License:Open Source License

@Override
public GroupPredicate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        JsonObject o = json.getAsJsonObject();
        return doDeserialize((GroupPredicate.PredicateType) context.deserialize(o.get("type"),
                GroupPredicate.PredicateType.class), o, context);
    }/*from w w  w.  j  a  v  a2s  . c  om*/
    throw new IllegalStateException("This is not a Message!");
}

From source file:org.cmg.jresp.json.GroupPredicateDeserializer.java

License:Open Source License

private GroupPredicate doDeserializeNotPredicate(JsonObject json, JsonDeserializationContext context) {
    return new Not((GroupPredicate) context.deserialize(json.get("arg"), GroupPredicate.class));
}