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.adr.datasql.orm.KindResultsJson.java

License:Apache License

@Override
public java.util.Date getTimestamp(String columnName) throws DataLinkException {
    JsonElement element = json.get(columnName);
    return element == null || element.isJsonNull() ? null
            : new Date(Instant.parse(element.getAsString()).toEpochMilli());
}

From source file:com.adr.datasql.orm.KindResultsJson.java

License:Apache License

@Override
public java.util.Date getDate(String columnName) throws DataLinkException {
    JsonElement element = json.get(columnName);
    return element == null || element.isJsonNull() ? null
            : new Date(LocalDate.parse(element.getAsString()).atStartOfDay(ZoneId.systemDefault()).toInstant()
                    .toEpochMilli());//from  www.  j  a v  a2  s .  c o m

}

From source file:com.adr.datasql.orm.KindResultsJson.java

License:Apache License

@Override
public java.util.Date getTime(String columnName) throws DataLinkException {
    JsonElement element = json.get(columnName);
    return element == null || element.isJsonNull() ? null
            : new Date(LocalTime.parse(element.getAsString()).atDate(LocalDate.ofEpochDay(0L))
                    .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
}

From source file:com.adr.datasql.orm.KindResultsJson.java

License:Apache License

@Override
public byte[] getBytes(String columnName) throws DataLinkException {
    JsonElement element = json.get(columnName);
    return element == null || element.isJsonNull() ? null : Base64.getDecoder().decode(element.getAsString());
}

From source file:com.adr.datasql.orm.KindResultsJson.java

License:Apache License

@Override
public Object getObject(String columnName) throws DataLinkException {
    JsonElement element = json.get(columnName);
    return element == null || element.isJsonNull() ? null : element.getAsString();
}

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);
    }//from w w  w.j  a v a2  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.agwego.common.GsonHelper.java

License:Open Source License

/**
 * Determine if the key is present in the given JsonArray
 * /*from   w w w  . j a v a  2  s.c om*/
 * @param key the key to lookup
 * @param array the JsonArray in question
 * @return is the key present in the JsonArray (a null array returns false)
 */
public static boolean in(final String key, final JsonArray array) {
    if (array == null)
        return false;

    for (JsonElement jElement : array)
        if (jElement.getAsString().equals(key))
            return true;

    return false;
}

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

License:Apache License

private Type typeForName(final JsonElement typeElem) {

    Type type = null;//from  ww  w .  j  a v  a  2s. c om
    try {

        String typeName = typeElem.getAsString();
        if (typeName.equals("card"))
            type = Card.class;
        else if (typeName.equals("bank"))
            type = Bank.class;
        else
            type = Class.forName(typeElem.getAsString());
    } catch (ClassNotFoundException e) {
        throw new JsonParseException(e);
    }

    return type;
}

From source file:com.android.tools.idea.stats.DistributionService.java

License:Apache License

@Nullable
private static List<Distribution> loadDistributionsFromJson(String jsonString) {
    Type fullRevisionType = new TypeToken<Revision>() {
    }.getType();//  w ww  . j a  v a 2 s .  c  o  m
    GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(fullRevisionType,
            new JsonDeserializer<Revision>() {
                @Override
                public Revision deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                        throws JsonParseException {
                    return Revision.parseRevision(json.getAsString());
                }
            });
    Gson gson = gsonBuilder.create();
    Type listType = new TypeToken<ArrayList<Distribution>>() {
    }.getType();
    try {
        return gson.fromJson(jsonString, listType);
    } catch (JsonParseException e) {
        LOG.error("Parse exception while reading distributions.json", e);
    }
    return null;
}

From source file:com.android.tools.idea.wizard.DistributionChartComponent.java

License:Apache License

@Nullable
private static List<Distribution> loadDistributionsFromJson(String jsonString) {
    Type fullRevisionType = new TypeToken<FullRevision>() {
    }.getType();//from  w w w.  ja  v a  2  s .  c o m
    GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(fullRevisionType,
            new JsonDeserializer<FullRevision>() {
                @Override
                public FullRevision deserialize(JsonElement json, Type typeOfT,
                        JsonDeserializationContext context) throws JsonParseException {
                    return FullRevision.parseRevision(json.getAsString());
                }
            });
    Gson gson = gsonBuilder.create();
    Type listType = new TypeToken<ArrayList<Distribution>>() {
    }.getType();
    try {
        return gson.fromJson(jsonString, listType);
    } catch (JsonParseException e) {
        LOG.error(e);
    }
    return null;
}