Example usage for com.google.gson JsonObject isJsonObject

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

Introduction

In this page you can find the example usage for com.google.gson JsonObject 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.ai2020lab.aiutils.common.JsonUtils.java

License:Apache License

/**
 * ?JSONObject??Stringvalue/*from   w ww  .  j a  va 2  s  . c om*/
 *
 * @param key ??
 * @return ??value
 */
public String getObjStringValue(String key, JsonObject obj) {
    if (key == null || key.equals("")) {
        // Key
        throw new IllegalArgumentException("?key?");
    }
    if (obj == null || !obj.isJsonObject()) {
        // JsonObject??JsonObject
        throw new IllegalArgumentException("?obj?JsonObject?");
    }
    if (!obj.has(key)) {
        // Key
        LogUtils.e(TAG, "objkey'" + key + "' ");
        return null;
    }
    return obj.get(key).getAsString();
}

From source file:com.ai2020lab.aiutils.common.JsonUtils.java

License:Apache License

/**
 * ?JSONObject??Integervalue//w w  w .ja  v a 2  s .  com
 *
 * @param key ??
 * @return ??value
 */
public Integer getObjIntValue(String key, JsonObject obj) {
    if (key == null || key.equals("")) {
        // Key
        throw new IllegalArgumentException("?key?");
    }
    if (obj == null || !obj.isJsonObject()) {
        // JsonObject??JsonObject
        throw new IllegalArgumentException("?obj?JsonObject?");
    }
    if (!obj.has(key)) {
        // Key
        LogUtils.e(TAG, "objkey'" + key + "' ");
        return null;
    }
    return obj.get(key).getAsInt();
}

From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java

License:Apache License

@Override
public String getEventId(JsonObject json) {
    if (json.isJsonObject() && json.getAsJsonObject().has(META)
            && json.getAsJsonObject().getAsJsonObject(META).has(ID)) {
        return json.getAsJsonObject().getAsJsonObject(META).get(ID).getAsString();
    }//from  www  .  java 2  s  .  c  om
    return null;
}

From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java

License:Apache License

public String getInputEventType(JsonObject json) {
    if (json.isJsonObject() && json.get(MSG_PARAMS).getAsJsonObject().has(META)
            && json.get(MSG_PARAMS).getAsJsonObject().getAsJsonObject(META).has(TYPE)) {
        return json.get(MSG_PARAMS).getAsJsonObject().getAsJsonObject(META).get(TYPE).getAsString();
    }//  w w  w . j ava2 s .  c o m
    return null;
}

From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java

License:Apache License

@Override
public String getEventType(JsonObject json) {
    if (json.isJsonObject() && json.getAsJsonObject().has(META)
            && json.getAsJsonObject().getAsJsonObject(META).has(TYPE)) {
        return json.getAsJsonObject().getAsJsonObject(META).get(TYPE).getAsString();
    }//  www .j a  v  a2s  .c o  m
    return null;
}

From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java

License:Apache License

/**
 * Returns Family Routing Key Word from the messaging library based on the
 * eiffel message eventType.//from   www.  ja  v  a  2s.  c o  m
 * 
 * @param JsonObject
 *            eiffelMessage
 * @return family routing key word in String format.
 */
private String getFamily(JsonObject eiffelMessage) {
    if (eiffelMessage.isJsonObject() && eiffelMessage.getAsJsonObject().has(META)
            && eiffelMessage.getAsJsonObject().getAsJsonObject(META).has(TYPE)) {
        return event.getFamilyRoutingKey(
                eiffelMessage.getAsJsonObject().getAsJsonObject(META).get(TYPE).getAsString());
    }
    return null;
}

From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java

License:Apache License

/**
 * Returns Type Routing Key Word from the messaging library based on the
 * eiffel message eventType.// w  ww  .  j a v  a2s.c  o  m
 * 
 * @param JsonObject
 *            eiffelMessage
 * @return type routing key word in String format.
 */
private String getType(JsonObject eiffelMessage) {
    if (eiffelMessage.isJsonObject() && eiffelMessage.getAsJsonObject().has(META)
            && eiffelMessage.getAsJsonObject().getAsJsonObject(META).has(TYPE)) {
        return event.getTypeRoutingKey(
                eiffelMessage.getAsJsonObject().getAsJsonObject(META).get(TYPE).getAsString());
    }
    return null;
}

From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java

License:Apache License

/**
 * Returns the domain Id from json formatted eiffel message.
 * //from   w w  w .  j  ava2  s .c  om
 * @param eiffelMessage
 *            eiffel message in json format
 * @return the domainId from eiffelMessage if domainId not available then
 *         returns the null value
 */
private String getDomainId(JsonObject eiffelMessage) {
    if (eiffelMessage.isJsonObject() && eiffelMessage.getAsJsonObject().has(META)
            && eiffelMessage.getAsJsonObject().getAsJsonObject(META).has(SOURCE)
            && eiffelMessage.getAsJsonObject().getAsJsonObject(META).getAsJsonObject(SOURCE).has(DOMAIN_ID)) {
        return eiffelMessage.getAsJsonObject().getAsJsonObject(META).getAsJsonObject(SOURCE).get(DOMAIN_ID)
                .getAsString();
    }
    return null;
}

From source file:com.github.api.v2.services.impl.FeedServiceImpl.java

License:Apache License

protected Feed unmarshall(String apiUrl) {
    JsonObject response = unmarshall(callApiGet(apiUrl));
    if (response.isJsonObject()) {
        JsonObject json = response.getAsJsonObject();
        int status = json.get("responseStatus").getAsInt();
        if (status != 200) {
            throw new GitHubException(json.get("responseDetails").getAsString());
        }// w w  w .  j  a v a 2 s. co  m
        JsonElement data = json.get("responseData");
        if (data != null) {
            return unmarshall(new TypeToken<Feed>() {
            }, data.getAsJsonObject().get("feed"));
        }
    }
    return null;
}

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

License:Apache License

public BigDecimal extractBigDecimalNamed(final String parameterName, final JsonObject element,
        final Locale locale, final Set<String> modifiedParameters) {
    BigDecimal value = null;/*from  w  w w  . ja va 2 s .  co 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 = convertFrom(valueAsString, parameterName, locale);
            }
        }
    }
    return value;
}