Example usage for com.google.gson JsonElement isJsonObject

List of usage examples for com.google.gson JsonElement isJsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonElement isJsonObject.

Prototype

public boolean isJsonObject() 

Source Link

Document

provides check for verifying if this element is a Json object or not.

Usage

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public Boolean extractBooleanNamed(final String parameterName, final JsonElement element,
        final Set<String> requestParamatersDetected) {
    Boolean value = null;// w ww .  j a  va 2  s.  c  o  m
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) {
            requestParamatersDetected.add(parameterName);

            final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive();
            value = primitive.getAsBoolean();
        }
    }
    return value;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public Long extractLongNamed(final String parameterName, final JsonElement element,
        final Set<String> parametersPassedInRequest) {
    Long longValue = null;//from  w w w.j av  a 2s. co  m
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) {
            parametersPassedInRequest.add(parameterName);
            final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive();
            final String stringValue = primitive.getAsString();
            if (StringUtils.isNotBlank(stringValue)) {
                longValue = Long.valueOf(stringValue);
            }
        }
    }
    return longValue;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public String extractStringNamed(final String parameterName, final JsonElement element,
        final Set<String> parametersPassedInRequest) {
    String stringValue = null;//from   ww w.  ja  v  a 2  s .  com
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) {
            parametersPassedInRequest.add(parameterName);
            final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive();
            final String valueAsString = primitive.getAsString();
            if (StringUtils.isNotBlank(valueAsString)) {
                stringValue = valueAsString;
            }
        }
    }
    return stringValue;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public BigDecimal extractBigDecimalWithLocaleNamed(final String parameterName, final JsonElement element,
        final Set<String> modifiedParameters) {
    BigDecimal value = null;//from ww  w  . j a  va  2 s  . c  o m
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        final Locale locale = extractLocaleValue(object);
        value = extractBigDecimalNamed(parameterName, object, locale, modifiedParameters);
    }
    return value;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public Integer extractIntegerWithLocaleNamed(final String parameterName, final JsonElement element,
        final Set<String> modifiedParameters) {
    Integer value = null;//  w w  w.ja va2s  .  c  om
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        final Locale locale = extractLocaleValue(object);
        value = extractIntegerNamed(parameterName, object, locale, modifiedParameters);
    }
    return value;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public Integer extractIntegerNamed(final String parameterName, final JsonElement element, final Locale locale,
        final Set<String> modifiedParameters) {
    Integer value = null;/*from   w w  w . j  a v  a 2s .  c  o  m*/
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) {
            modifiedParameters.add(parameterName);
            final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive();
            final String valueAsString = primitive.getAsString();
            if (StringUtils.isNotBlank(valueAsString)) {
                value = convertToInteger(valueAsString, parameterName, locale);
            }
        }
    }
    return value;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

/**
 * Method used to extract integers from unformatted strings. Ex: "1" ,
 * "100002" etc//  w  w w.j av a  2 s .co  m
 *
 * Please note that this method does not support extracting Integers from
 * locale specific formatted strings Ex "1,000" etc
 *
 * @param parameterName
 * @param element
 * @param parametersPassedInRequest
 * @return
 */
public Integer extractIntegerSansLocaleNamed(final String parameterName, final JsonElement element,
        final Set<String> parametersPassedInRequest) {
    Integer intValue = null;
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) {
            parametersPassedInRequest.add(parameterName);
            final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive();
            final String stringValue = primitive.getAsString();
            if (StringUtils.isNotBlank(stringValue)) {
                intValue = convertToIntegerSanLocale(stringValue, parameterName);
            }
        }
    }
    return intValue;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public String[] extractArrayNamed(final String parameterName, final JsonElement element,
        final Set<String> parametersPassedInRequest) {
    String[] arrayValue = null;//from w  ww  . ja  v  a  2  s .  c  o  m
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        if (object.has(parameterName)) {
            parametersPassedInRequest.add(parameterName);
            final JsonArray array = object.get(parameterName).getAsJsonArray();
            arrayValue = new String[array.size()];
            for (int i = 0; i < array.size(); i++) {
                arrayValue[i] = array.get(i).getAsString();
            }
        }
    }
    return arrayValue;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public JsonArray extractJsonArrayNamed(final String parameterName, final JsonElement element) {
    JsonArray jsonArray = null;/* w  w  w  . j  a v  a  2s  . c  o m*/

    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        if (object.has(parameterName)) {
            jsonArray = object.get(parameterName).getAsJsonArray();
        }
    }

    return jsonArray;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

License:Apache License

public JsonObject extractJsonObjectNamed(final String parameterName, final JsonElement element) {
    JsonObject jsonObject = null;/*from  w  w  w  .ja v  a2  s. c o  m*/

    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();
        if (object.has(parameterName)) {
            jsonObject = object.get(parameterName).getAsJsonObject();
        }
    }

    return jsonObject;
}