Example usage for com.google.gson.internal LinkedTreeMap keySet

List of usage examples for com.google.gson.internal LinkedTreeMap keySet

Introduction

In this page you can find the example usage for com.google.gson.internal LinkedTreeMap keySet.

Prototype

KeySet keySet

To view the source code for com.google.gson.internal LinkedTreeMap keySet.

Click Source Link

Usage

From source file:com.jaguarlandrover.rvi.Service.java

License:Mozilla Public License

HashMap unwrap(ArrayList<LinkedTreeMap> parameters) {
    HashMap unwrapped = new HashMap();

    for (LinkedTreeMap element : parameters)
        for (Object key : element.keySet())
            unwrapped.put(key, element.get(key));

    return unwrapped;
}

From source file:com.microsoft.activitytracker.Activities.ItemActivity.java

License:Open Source License

private void getDetailInfo() {
    HashMap<String, String> queries = new HashMap<String, String>();
    queries.put("$select", Constants.CONTACT_SELECT);

    NetworkCalls.oDataGetRequest(this, String.format("ContactSet(guid'%s')", mThisEntity.getId()), queries,
            new Callback<LinkedTreeMap<String, Object>>() {

                @Override/*w w w.  j a va 2  s .  c o m*/
                public void success(LinkedTreeMap<String, Object> stringObjectLinkedTreeMap,
                        Response response) {
                    // drill into the response to get to the properties which is in the 'd' namespace
                    LinkedTreeMap<String, Object> propResponse = (LinkedTreeMap<String, Object>) stringObjectLinkedTreeMap
                            .get("d");

                    // pull the keys of the properties and check if we have it yet
                    // if not add them to the entity attributes hashmap
                    Set<String> keys = propResponse.keySet();
                    for (String key : keys) {
                        if (!mThisEntity.attributes.containsKey(key.toLowerCase())) {
                            mThisEntity.attributes.put(key.toLowerCase(), propResponse.get(key));
                        }
                    }

                    loadItemDetails();
                }

                @Override
                public void failure(RetrofitError error) {
                    error.getCause().printStackTrace();
                }
            });
}

From source file:com.sat.common.CommonFunctions.java

License:Open Source License

/**
 * Json to linked has map.//from w  ww.j  av a 2 s  .co m
 *
 * @param strReturn the str return
 * @return the linked hash map
 */
public LinkedHashMap<String, String> jsonToLinkedHasMap(String strReturn) {
    LinkedHashMap<String, String> lhm = new LinkedHashMap<String, String>();
    Gson gson = new Gson();
    LinkedTreeMap<?, ?> result = gson.fromJson(strReturn, LinkedTreeMap.class);
    Set<?> keys = result.keySet();
    for (Iterator<?> i = keys.iterator(); i.hasNext();) {
        Object key = i.next();
        Object value = (Object) result.get(key);

        System.out.println(key + " <=> " + value);
        String key1 = (String) key;
        String value1;
        try {
            value1 = (String) value;
        } catch (ClassCastException e) {
            value1 = value.toString();
        }
        lhm.put(key1, value1);
    }
    return lhm;
}

From source file:com.tremolosecurity.unison.openshiftv3.wf.OpenShiftWorkflows.java

License:Apache License

@Override
public List<Map<String, String>> generateWorkflows(WorkflowType wf, ConfigManager cfg,
        HashMap<String, Attribute> params) throws ProvisioningException {
    ArrayList<Map<String, String>> wfData = new ArrayList<Map<String, String>>();

    String targetName = params.get("target").getValues().get(0);

    HashSet<String> nameFilter = new HashSet<String>();
    Attribute attr = params.get("filter");
    if (attr != null) {
        nameFilter.addAll(attr.getValues());
    }/*from  w ww  .  j av a 2  s .  c o  m*/

    OpenShiftTarget target = (OpenShiftTarget) cfg.getProvisioningEngine().getTarget(targetName).getProvider();

    String kind = params.get("kind").getValues().get(0);

    try {
        String token = target.getAuthToken();

        HttpCon con = target.createClient();

        try {

            String json = target.callWS(token, con, kind);

            Gson gson = new Gson();
            TypeToken<com.tremolosecurity.unison.openshiftv3.model.List<Item>> tokenType = new TypeToken<com.tremolosecurity.unison.openshiftv3.model.List<Item>>() {
            };
            com.tremolosecurity.unison.openshiftv3.model.List<Item> list = gson.fromJson(json,
                    tokenType.getType());

            for (Item item : list.getItems()) {
                HashMap<String, String> wfParams = new HashMap<String, String>();
                String name = (String) item.getMetadata().get("name");

                if (nameFilter.contains(name)) {
                    continue;
                }

                wfParams.put("name", name);
                if (item.getMetadata().containsKey("annotations")) {
                    com.google.gson.internal.LinkedTreeMap annotations = (com.google.gson.internal.LinkedTreeMap) item
                            .getMetadata().get("annotations");
                    for (Object key : annotations.keySet()) {
                        String keyName = (String) key;
                        keyName = keyName.replace("-", "_");
                        keyName = keyName.replace(".", "_");
                        wfParams.put((String) keyName, (String) annotations.get(key));
                    }
                }

                wfData.add(wfParams);
            }

        } finally {
            con.getBcm().close();
            con.getHttp().close();
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not load", e);
    }
    return wfData;
}

From source file:eu.freme.eservices.pipelines.serialization.Serializer.java

License:Apache License

/**
 * Checks if all fields in the JSON string are valid field names of the {@link SerializedRequest} class. Throws an
 * exception if not valid.// w  w w. j a va 2  s .c o m
 * @param serializedRequests   The JSON string to check; it should represent a list of {@link SerializedRequest} objects.
 * @throws JsonSyntaxException   A field is not recognized.
 */
private static void checkOnRequestsMembers(final String serializedRequests) {
    Object serReqObj = gson.fromJson(serializedRequests, Object.class);
    if (!(serReqObj instanceof ArrayList)) {
        throw new JsonSyntaxException("Expected an array of requests");
    }
    ArrayList<LinkedTreeMap> requests = (ArrayList<LinkedTreeMap>) serReqObj;
    for (int reqNr = 0; reqNr < requests.size(); reqNr++) {
        LinkedTreeMap map = requests.get(reqNr);
        for (Object o : map.keySet()) {
            String fieldName = (String) o;
            if (!requestFieldNames.contains(fieldName)) {
                throw new JsonSyntaxException(
                        "request " + (reqNr + 1) + ": field \"" + fieldName + "\" not known.");
            }
        }
    }
}

From source file:eu.freme.eservices.pipelines.serialization.Serializer.java

License:Apache License

private static void checkOnPipelineMembers(final String pipeline) {
    LinkedTreeMap<String, String> pipelineObject = (LinkedTreeMap<String, String>) gson.fromJson(pipeline,
            Object.class);
    for (String fieldName : pipelineObject.keySet()) {
        if (!pipelineFieldNames.contains(fieldName)) {
            throw new JsonSyntaxException("field \"" + fieldName + "\" not known.");
        }//from   www .j a v  a 2 s  . c o m
    }
}

From source file:session.WebSession.java

public static void addEachWebSession(HttpSession mysession, String data) {
    String key = "";
    Object value;//from  www  .j a v  a  2 s .  c o  m
    Gson gson = new Gson();
    LinkedTreeMap obj = gson.fromJson(data, LinkedTreeMap.class);
    for (Object e : obj.keySet()) {
        SessionListener.setSessionAttribute(mysession, String.valueOf(e), obj.get(e));
    }
}

From source file:StorageHelper.CreatorHelper.java

License:Apache License

/**
 * create a data storage from given data using the right type it really is
 * method finds out the type of the object and then adds it to collection the right way for that type
 * @param data Object of data//from  w  w w  . j  av a  2  s.c  o m
 * @return DataStorage with data populated
 */
public static Storage createDataStorage(Object data) {
    boolean alreadyEntered = false;
    Storage store = new Storage();
    //if it is a default type then don't let it match anything else
    Class[] dataTypes = { Integer.class, String.class, int.class, Double.class, double.class, boolean.class,
            Boolean.class };

    //if data is null we can return an empty data storage
    if (data == null) {
        return store;
    }

    //skip all of these things if it is a data type not collection
    if (!Arrays.asList(dataTypes).contains(data.getClass())) {

        //find what type the Object data is and cast it to that
        //add to collection as the right type it is
        if (data.getClass().getTypeName().contains("ArrayList")) {
            store.addArray((ArrayList) data);
            alreadyEntered = true;
        } else if (data.getClass().getTypeName().contains("HashMap")) {
            store.addMap((HashMap) data);
            alreadyEntered = true;
        } else if (data.getClass().getTypeName().contains("JSONArray")) {
            store.addJson((JSONArray) data);
            alreadyEntered = true;
        } else if (data.getClass().getTypeName().contains("JSONObject")) {
            store.addJson((JSONObject) data);
            alreadyEntered = true;
        }

        //gson uses this linked tree map type, this will convert it to Data Storage
        else {
            if (data.getClass().getTypeName().contains("LinkedTreeMap")) {
                LinkedTreeMap<String, Object> treeData = (LinkedTreeMap) data;
                for (String key : treeData.keySet())
                    store.put(key, treeData.get(key));
            }
            //this could be many things, but not a string
            else if (!data.getClass().getTypeName().contains("String"))
                if (!data.toString().isEmpty())
                    store.addModel(data);
            alreadyEntered = true;
        }
    }

    //if nothing is added just add the object at index 0
    if (store.size() < 1 && !data.toString().isEmpty() && !alreadyEntered)
        store.put("0", data);

    return store;
}

From source file:tech.mcprison.prison.ranks.data.RankPlayer.java

License:Open Source License

public RankPlayer(Document document) {
    this.uid = UUID.fromString((String) document.get("uid"));
    LinkedTreeMap<String, Object> ranksLocal = (LinkedTreeMap<String, Object>) document.get("ranks");
    LinkedTreeMap<String, Object> prestigeLocal = (LinkedTreeMap<String, Object>) document.get("prestige");

    this.ranks = new HashMap<>();
    for (String key : ranksLocal.keySet()) {
        ranks.put(key, RankUtil.doubleToInt(ranksLocal.get(key)));
    }// w  ww  .java 2s . co m
    this.prestige = new HashMap<>();
    for (String key : prestigeLocal.keySet()) {
        prestige.put(key, RankUtil.doubleToInt(prestigeLocal.get(key)));
    }
}