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:co.cask.cdap.proto.codec.WorkflowNodeCodec.java

License:Apache License

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

    WorkflowNodeType type = context.deserialize(jsonObj.get("nodeType"), WorkflowNodeType.class);

    switch (type) {
    case ACTION://from w  w  w.  ja  v a2  s .c o m
        return context.deserialize(json, WorkflowActionNode.class);
    case FORK:
        return context.deserialize(json, WorkflowForkNode.class);
    case CONDITION:
        return context.deserialize(json, WorkflowConditionNode.class);
    }
    return null;
}

From source file:co.cask.cdap.proto.codec.WorkflowNodeThrowableCodec.java

License:Apache License

@Override
public WorkflowNodeThrowable deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    String className = jsonObj.get("className").getAsString();
    String message = jsonObj.get("message").getAsString();
    JsonArray stackTraces = jsonObj.get("stackTraces").getAsJsonArray();
    StackTraceElement[] stackTraceElements = context.deserialize(stackTraces, StackTraceElement[].class);
    JsonElement cause = jsonObj.get("cause");
    WorkflowNodeThrowable dfc = null;/*from   w  w  w.j a v a2 s  .  co m*/
    if (cause != null) {
        dfc = context.deserialize(cause, WorkflowNodeThrowable.class);
    }
    return new WorkflowNodeThrowable(className, message, stackTraceElements, dfc);
}

From source file:co.cask.tigon.internal.app.FlowletSpecificationCodec.java

License:Apache License

@Override
public FlowletSpecification 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();
    String description = jsonObj.get("description").getAsString();
    FailurePolicy policy = FailurePolicy.valueOf(jsonObj.get("failurePolicy").getAsString());
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    ResourceSpecification resources = context.deserialize(jsonObj.get("resources"),
            new TypeToken<ResourceSpecification>() {
            }.getType());// www.  j av a 2s . c o m
    int maxInstances = jsonObj.get("maxInstances").getAsInt();

    return new DefaultFlowletSpecification(className, name, description, policy, properties, resources,
            maxInstances);
}

From source file:com.activiti.client.api.model.deserializer.ResultListDeserializer.java

License:Apache License

@Override
public ResultList<T> deserialize(JsonElement je, Type type, JsonDeserializationContext jdc)
        throws JsonParseException {
    JsonArray entries = null;/*w w w . j a va  2 s. co  m*/
    if (je.getAsJsonObject().has(RequestConstant.DATA)) {
        entries = je.getAsJsonObject().get(RequestConstant.DATA).getAsJsonArray();
    }

    final List<T> result = new ArrayList<>();
    T obj = null;
    if (entries != null) {
        for (Object entry : entries) {
            obj = jdc.deserialize((JsonElement) entry, clazz);
            result.add(obj);
        }
    }

    ResultList<T> resultList = new ResultList<>();
    resultList.setList(result);
    resultList.setSize(je.getAsJsonObject().has(RequestConstant.SIZE)
            ? je.getAsJsonObject().get(RequestConstant.SIZE).getAsInt()
            : 0);
    resultList.setStart(je.getAsJsonObject().has(RequestConstant.START)
            ? je.getAsJsonObject().get(RequestConstant.START).getAsInt()
            : 0);
    resultList.setTotal(je.getAsJsonObject().has(RequestConstant.TOTAL)
            ? je.getAsJsonObject().get(RequestConstant.TOTAL).getAsInt()
            : 0);

    return resultList;
}

From source file:com.adyen.deserializer.MarketPayNotificationMessageDeserializer.java

License:MIT License

@Override
public GenericNotification deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    JsonObject jsonObject = jsonElement.getAsJsonObject();

    JsonElement jsonType = jsonObject.get("eventType");
    String eventType = jsonType.getAsString();

    if (GenericNotification.EventTypeEnum.ACCOUNT_CREATED.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, AccountCreatedNotification.class);
    }/* w w w  .ja v  a  2  s  .  c o m*/
    if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_CREATED.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, AccountHolderCreatedNotification.class);
    }
    if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_LIMIT_REACHED.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, AccountHolderLimitReachedNotification.class);
    }
    if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_VERIFICATION.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, AccountHolderVerificationNotification.class);
    }
    if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_STATUS_CHANGE.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, AccountHolderStatusChangeNotification.class);
    }
    if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_PAYOUT.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, AccountHolderPayoutNotification.class);
    }
    if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_UPDATED.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, AccountHolderUpdatedNotification.class);
    }
    if (GenericNotification.EventTypeEnum.BENEFICIARY_SETUP.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, BeneficiarySetupNotification.class);
    }
    if (GenericNotification.EventTypeEnum.SCHEDULED_REFUNDS.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, ScheduledRefundsNotification.class);
    }
    if (GenericNotification.EventTypeEnum.COMPENSATE_NEGATIVE_BALANCE.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, CompensateNegativeBalanceNotification.class);
    }
    if (GenericNotification.EventTypeEnum.PAYMENT_FAILURE.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, PaymentFailureNotification.class);
    }
    if (GenericNotification.EventTypeEnum.REPORT_AVAILABLE.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, ReportAvailableNotification.class);
    }
    if (GenericNotification.EventTypeEnum.TRANSFER_FUNDS.toString().equalsIgnoreCase(eventType)) {
        return jsonDeserializationContext.deserialize(jsonElement, TransferFundsNotification.class);
    }

    return jsonDeserializationContext.deserialize(jsonElement, GenericNotification.class);
}

From source file:com.alfresco.client.api.common.deserializer.PagingDeserializer.java

License:Apache License

@Override
public ResultPaging<T> deserialize(JsonElement je, Type type, JsonDeserializationContext jdc)
        throws JsonParseException {
    JsonObject pagination = null;/*from ww w .  j  a v a 2 s.  c o m*/
    JsonArray entries = null;
    if (je.getAsJsonObject().has(PublicAPIConstant.LIST_VALUE)) {
        pagination = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject()
                .get(PublicAPIConstant.PAGINATION_VALUE).getAsJsonObject();
        entries = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject()
                .get(PublicAPIConstant.ENTRIES_VALUE).getAsJsonArray();
    }

    final List<T> result = new ArrayList<>();
    T obj = null;
    for (Object entry : entries) {
        obj = jdc.deserialize((JsonElement) entry, clazz);
        result.add(obj);
    }

    PaginationRepresentation paging = jdc.deserialize(pagination, PaginationRepresentation.class);

    return new ResultPaging(result, paging);
}

From source file:com.alfresco.client.api.core.model.deserializer.FavoriteEntryDeserializer.java

License:Apache License

@Override
public FavoriteRepresentation deserialize(JsonElement je, Type type, JsonDeserializationContext jdc)
        throws JsonParseException {
    JsonElement entry = je;/* w ww. j  a  va2  s. co  m*/
    if (je.getAsJsonObject().has(PublicAPIConstant.ENTRY_VALUE)) {
        entry = je.getAsJsonObject().get(PublicAPIConstant.ENTRY_VALUE);
    }

    FavoriteRepresentation favorite = null;
    JsonObject target = entry.getAsJsonObject().get("target").getAsJsonObject();
    if (target.has("file")) {
        favorite = jdc.deserialize(entry, FavoriteNodeRepresentation.class);
        NodeRepresentation file = jdc.deserialize(target.get("file").getAsJsonObject(),
                NodeRepresentation.class);
        favorite.setTarget(file);
    } else if (target.has("folder")) {
        favorite = jdc.deserialize(entry, FavoriteNodeRepresentation.class);
        NodeRepresentation file = jdc.deserialize(target.get("folder").getAsJsonObject(),
                NodeRepresentation.class);
        favorite.setTarget(file);
    } else if (target.has("site")) {
        favorite = jdc.deserialize(entry, FavoriteSiteRepresentation.class);
        SiteRepresentation site = jdc.deserialize(target.get("site").getAsJsonObject(),
                SiteRepresentation.class);
        favorite.setTarget(site);
    }

    return favorite;
}

From source file:com.alfresco.client.api.search.deserializer.ResultSetPagingDeserializer.java

License:Apache License

@Override
public ResultSetRepresentation<T> deserialize(JsonElement je, Type type, JsonDeserializationContext jdc)
        throws JsonParseException {
    JsonObject contextInfo = null;//w ww .  j  a  v a2 s . c o m
    JsonObject pagination = null;
    JsonArray entries = null;
    if (je.getAsJsonObject().has(PublicAPIConstant.LIST_VALUE)) {
        pagination = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject()
                .get(PublicAPIConstant.PAGINATION_VALUE).getAsJsonObject();
        entries = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject()
                .get(PublicAPIConstant.ENTRIES_VALUE).getAsJsonArray();

        if (je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject()
                .has(PublicAPIConstant.CONTEXT_VALUE)) {
            contextInfo = je.getAsJsonObject().get(PublicAPIConstant.LIST_VALUE).getAsJsonObject()
                    .get(PublicAPIConstant.CONTEXT_VALUE).getAsJsonObject();
        }
    }

    final List<T> result = new ArrayList<>();
    T obj = null;
    for (Object entry : entries) {
        obj = jdc.deserialize((JsonElement) entry, clazz);
        result.add(obj);
    }

    PaginationRepresentation paging = jdc.deserialize(pagination, PaginationRepresentation.class);
    ResultSetContext context = jdc.deserialize(contextInfo, ResultSetContext.class);

    return new ResultSetRepresentation<T>(result, context, paging);
}

From source file:com.alignace.chargeio.mapper.gson.adapter.IPaymentTypeAdapter.java

License:Apache License

public IPaymentMethod deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    final JsonObject wrapper = (JsonObject) json;
    final JsonElement typeName = get(wrapper, "type");
    final Type actualType = typeForName(typeName);
    IPaymentMethod response = context.deserialize(json, actualType);
    return response;
}

From source file:com.alignace.chargeio.mapper.gson.adapter.TypeAdapter.java

License:Apache License

public F deserialize(JsonElement json, Type type, JsonDeserializationContext context)
        throws JsonParseException {

    return context.deserialize(json, getMyType());
}