Example usage for com.google.gson JsonObject entrySet

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

Introduction

In this page you can find the example usage for com.google.gson JsonObject entrySet.

Prototype

public Set<Map.Entry<String, JsonElement>> entrySet() 

Source Link

Document

Returns a set of members of this object.

Usage

From source file:com.flipkart.android.proteus.parser.ParseHelper.java

License:Apache License

public static Pair<int[], JsonElement> parseState(JsonObject stateObject) {

    //drawable/* w w  w.j a  va 2 s .co  m*/
    JsonElement drawableJson = stateObject.get(DRAWABLE_STR);
    if (null != drawableJson) {

        //states
        Set<Map.Entry<String, JsonElement>> entries = stateObject.entrySet();
        List<Integer> statesToReturn = new ArrayList<>();
        for (Map.Entry<String, JsonElement> entry : entries) {
            JsonElement value = entry.getValue();
            String state = entry.getKey();
            Integer stateInteger = sStateMap.get(state);
            if (stateInteger != null) {
                String stateValue = value.getAsString();
                //e.g state_pressed = true state_pressed = false
                statesToReturn.add(ParseHelper.parseBoolean(stateValue) ? stateInteger : -stateInteger);
            }
        }

        int[] statesToReturnInteger = new int[statesToReturn.size()];
        for (int i = 0; i < statesToReturn.size(); i++) {
            statesToReturnInteger[i] = statesToReturn.get(i);
        }

        return new Pair<>(statesToReturnInteger, drawableJson);
    }
    return null;
}

From source file:com.flipkart.android.proteus.toolbox.Utils.java

License:Apache License

public static JsonObject addElements(JsonObject destination, JsonObject source, boolean override) {
    for (Map.Entry<String, JsonElement> entry : source.entrySet()) {
        if (!override && destination.get(entry.getKey()) != null) {
            continue;
        }/*  ww  w .  jav a2  s .co m*/
        destination.add(entry.getKey(), entry.getValue());
    }
    return destination;
}

From source file:com.flipkart.android.proteus.toolbox.Utils.java

License:Apache License

public static JsonObject mergeLayouts(JsonObject destination, JsonObject source) {
    JsonObject layout = new JsonObject();
    for (Map.Entry<String, JsonElement> entry : destination.entrySet()) {
        layout.add(entry.getKey(), entry.getValue());
    }//from   w w w  . jav a 2 s. co  m
    boolean hasType = layout.has(ProteusConstants.TYPE);
    for (Map.Entry<String, JsonElement> entry : source.entrySet()) {
        if (ProteusConstants.TYPE.equals(entry.getKey()) && hasType) {
            continue;
        }
        if (ProteusConstants.DATA_CONTEXT.equals(entry.getKey())) {
            continue;
        }
        layout.add(entry.getKey(), entry.getValue());
    }
    return layout;
}

From source file:com.flipkart.polyguice.config.JsonConfiguration.java

License:Apache License

private void flatten(String prefix, JsonElement element) {
    if (element.isJsonPrimitive()) {
        JsonPrimitive jsonPrim = element.getAsJsonPrimitive();
        if (jsonPrim.isBoolean()) {
            configTab.put(prefix, jsonPrim.getAsBoolean());
        } else if (jsonPrim.isNumber()) {
            configTab.put(prefix, jsonPrim.getAsNumber());
        } else if (jsonPrim.isString()) {
            configTab.put(prefix, jsonPrim.getAsString());
        }/*from  ww  w. j a va  2  s.  c om*/
    } else if (element.isJsonObject()) {
        JsonObject jsonObj = element.getAsJsonObject();
        for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
            String prefix1 = ((prefix != null) ? prefix + "." : "") + entry.getKey();
            flatten(prefix1, entry.getValue());
        }
    }
}

From source file:com.fooock.shodan.model.dns.DnsHostnameDeserializer.java

License:Open Source License

@Override
public List<DnsHostname> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    final List<DnsHostname> dnsHostnames = new ArrayList<>();

    if (json.isJsonNull()) {
        return dnsHostnames;
    }//from w  ww  .j  a v  a2 s .c o m
    JsonObject jsonObject = json.getAsJsonObject();
    if (jsonObject == null) {
        return dnsHostnames;
    }
    for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        String key = entry.getKey();
        JsonElement value = entry.getValue();

        if (value == null || value.isJsonNull()) {
            String[] unknown = new String[] { "" };
            DnsHostname dnsHostname = new DnsHostname(key, unknown);
            dnsHostnames.add(dnsHostname);
            continue;
        }

        String hostnameString = value.getAsString();
        if (hostnameString != null && !hostnameString.isEmpty()) {
            String[] hostnames = hostnameString.split(",");

            DnsHostname dnsHostname = new DnsHostname(key, hostnames);
            dnsHostnames.add(dnsHostname);
        }
    }
    return dnsHostnames;
}

From source file:com.fooock.shodan.model.dns.DnsIpDeserializer.java

License:Open Source License

@Override
public List<DnsIp> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    final List<DnsIp> dns = new ArrayList<>();

    if (json.isJsonNull()) {
        return dns;
    }/*  ww w.j  ava  2  s  .co m*/
    JsonObject jsonObject = json.getAsJsonObject();
    for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        String key = entry.getKey();
        JsonElement value = entry.getValue();

        DnsIp dnsIp = new DnsIp(key, value.getAsString());
        dns.add(dnsIp);
    }
    return dns;
}

From source file:com.fooock.shodan.model.host.FacetReportDeserializer.java

License:Open Source License

private List<Facet> getFacets(JsonObject facetsElement) {
    final List<Facet> facets = new ArrayList<>();

    for (Map.Entry<String, JsonElement> entry : facetsElement.entrySet()) {
        String key = entry.getKey();
        JsonElement property = entry.getValue();

        JsonArray jsonArray = property.getAsJsonArray();
        final List<Property> properties = new ArrayList<>(jsonArray.size());
        for (JsonElement element : jsonArray) {
            JsonObject facetElement = element.getAsJsonObject();
            JsonElement count = facetElement.get("count");
            JsonElement value = facetElement.get("value");

            final Property prop = new Property(count.getAsInt(), value.getAsString());
            properties.add(prop);/* w  ww .  ja  v  a2 s.co m*/
        }
        final Facet facet = new Facet(key, properties);
        facets.add(facet);
    }
    return facets;
}

From source file:com.fooock.shodan.model.protocol.ProtocolDeserializer.java

License:Open Source License

@Override
public List<Protocol> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    final List<Protocol> protocols = new ArrayList<>();

    if (json.isJsonNull()) {
        return protocols;
    }/* w  w  w  .  ja  v a 2s. c o m*/
    JsonObject jsonObject = json.getAsJsonObject();
    if (jsonObject.isJsonNull()) {
        return protocols;
    }

    for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        String key = entry.getKey();
        JsonElement value = entry.getValue();

        Protocol protocol = new Protocol(key, value.getAsString());
        protocols.add(protocol);
    }
    return protocols;
}

From source file:com.fooock.shodan.model.user.HttpHeaderDeserializer.java

License:Open Source License

@Override
public HttpHeader deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonNull()) {
        return new HttpHeader(Collections.emptyList());
    }/*from   w w w. j a  v  a 2  s.c  o  m*/
    JsonObject jsonObject = json.getAsJsonObject();
    if (jsonObject.isJsonNull()) {
        return new HttpHeader(Collections.emptyList());
    }

    final List<Value> values = new ArrayList<>();
    for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        String key = entry.getKey();
        JsonElement value = entry.getValue();

        values.add(new Value(key, value.getAsString()));
    }
    return new HttpHeader(values);
}

From source file:com.frontier45.flume.sink.elasticsearch2.ElasticSearchLogStashEventSerializer.java

License:Apache License

private void appendBody(XContentBuilder builder, Event event) throws IOException {
    byte[] body = event.getBody();
    String content = new String(body, "utf-8");
    if (logger.isDebugEnabled()) {
        logger.debug("msg===>" + content);
    }//from   w ww  . j  a va2s  .  co  m
    //        ContentBuilderUtil.appendField(builder, "@message", body);
    Map<String, String> headers = Maps.newHashMap(event.getHeaders());
    String format = headers.get("format");
    if ("json".equals(format)) {
        try {
            JsonObject jsonObject = parser.parse(content).getAsJsonObject();
            for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
                builder.field(entry.getKey(), getValue(entry.getValue()));
            }
        } catch (Exception e) {
            builder.field("@message", content);
        }
    } else {
        XContentType contentType = XContentFactory.xContentType(body);
        if (contentType == null) {
            builder.field("@message", content);
        } else {
            ContentBuilderUtil.addComplexField(builder, "@message", contentType, body);
        }
    }
}