Search in sources :

Example 11 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project fitpay-android-sdk by fitpay.

the class ObjectConverter method convertToSimpleMap.

public static <T> Map<String, Object> convertToSimpleMap(T object) {
    Gson gson = new Gson();
    JsonElement objectAsJson = gson.toJsonTree(object);
    LinkedTreeMap objectAsMap = gson.fromJson(objectAsJson, LinkedTreeMap.class);
    Map<String, Object> resultMap = new HashMap<>();
    iterateThroughMap(0, "", objectAsMap, resultMap);
    return resultMap;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson)

Example 12 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project java-sdk by optimizely.

the class AudienceGsonDeserializer method parseConditions.

private Condition parseConditions(List<Object> rawObjectList) {
    List<Condition> conditions = new ArrayList<Condition>();
    String operand = (String) rawObjectList.get(0);
    for (int i = 1; i < rawObjectList.size(); i++) {
        Object obj = rawObjectList.get(i);
        if (obj instanceof List) {
            List<Object> objectList = (List<Object>) rawObjectList.get(i);
            conditions.add(parseConditions(objectList));
        } else {
            LinkedTreeMap<String, String> conditionMap = (LinkedTreeMap<String, String>) rawObjectList.get(i);
            conditions.add(new UserAttribute(conditionMap.get("name"), conditionMap.get("type"), conditionMap.get("value")));
        }
    }
    Condition condition;
    if (operand.equals("and")) {
        condition = new AndCondition(conditions);
    } else if (operand.equals("or")) {
        condition = new OrCondition(conditions);
    } else {
        condition = new NotCondition(conditions.get(0));
    }
    return condition;
}
Also used : Condition(com.optimizely.ab.config.audience.Condition) OrCondition(com.optimizely.ab.config.audience.OrCondition) NotCondition(com.optimizely.ab.config.audience.NotCondition) AndCondition(com.optimizely.ab.config.audience.AndCondition) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) NotCondition(com.optimizely.ab.config.audience.NotCondition) UserAttribute(com.optimizely.ab.config.audience.UserAttribute) ArrayList(java.util.ArrayList) AndCondition(com.optimizely.ab.config.audience.AndCondition) JsonObject(com.google.gson.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) OrCondition(com.optimizely.ab.config.audience.OrCondition)

Example 13 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project maple-ir by LLVM-but-worse.

the class ObjectTypeAdapter method read.

@Override
public Object read(JsonReader in) throws IOException {
    JsonToken token = in.peek();
    switch(token) {
        case BEGIN_ARRAY:
            List<Object> list = new ArrayList<Object>();
            in.beginArray();
            while (in.hasNext()) {
                list.add(read(in));
            }
            in.endArray();
            return list;
        case BEGIN_OBJECT:
            Map<String, Object> map = new LinkedTreeMap<String, Object>();
            in.beginObject();
            while (in.hasNext()) {
                map.put(in.nextName(), read(in));
            }
            in.endObject();
            return map;
        case STRING:
            return in.nextString();
        case NUMBER:
            return in.nextDouble();
        case BOOLEAN:
            return in.nextBoolean();
        case NULL:
            in.nextNull();
            return null;
        default:
            throw new IllegalStateException();
    }
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) ArrayList(java.util.ArrayList) JsonToken(com.google.gson.stream.JsonToken)

Example 14 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project bitsquare by bitsquare.

the class BtcAverageProvider method getMap.

private Map<String, PriceData> getMap(String json) {
    Map<String, PriceData> marketPriceMap = new HashMap<>();
    LinkedTreeMap<String, Object> treeMap = new Gson().<LinkedTreeMap<String, Object>>fromJson(json, LinkedTreeMap.class);
    treeMap.entrySet().stream().forEach(e -> {
        Object value = e.getValue();
        if (value instanceof LinkedTreeMap) {
            LinkedTreeMap<String, Object> data = (LinkedTreeMap) value;
            String currencyCode = e.getKey().substring(3);
            marketPriceMap.put(currencyCode, new PriceData(currencyCode, (double) data.get("ask"), (double) data.get("bid"), (double) data.get("last")));
        }
    });
    return marketPriceMap;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) HashMap(java.util.HashMap) PriceData(io.bitsquare.pricefeed.PriceData) Gson(com.google.gson.Gson)

Example 15 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project instructure-android by instructure.

the class QuizSubmissionQuestionListRecyclerAdapter method addMultipleDropdown.

private void addMultipleDropdown(final QuizSubmissionQuestion baseItem, QuizMultipleDropdownViewHolder holder, int position, int courseColor) {
    addAnsweredQuestion(baseItem);
    QuizMultipleDropdownBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), embeddedWebViewCallback, webViewClientCallback, new QuizPostMultipleDropdown() {

        @Override
        public void postMultipleDropdown(final long questionId, HashMap<String, Long> answers) {
            QuizManager.postQuizQuestionMultipleDropdown(quizSubmission, questionId, answers, true, new StatusCallback<QuizSubmissionQuestionResponse>() {

                @Override
                public void onResponse(@NonNull Response<QuizSubmissionQuestionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    if (type == ApiType.CACHE)
                        return;
                    QuizSubmissionQuestionResponse quizSubmissionQuestionResponse = response.body();
                    if (quizSubmissionQuestionResponse.getQuizSubmissionQuestions() != null) {
                        for (QuizSubmissionQuestion question : quizSubmissionQuestionResponse.getQuizSubmissionQuestions()) {
                            if (baseItem.getId() == question.getId()) {
                                baseItem.setAnswer(question.getAnswer());
                            }
                        }
                        // make sure each answer has a match
                        int numAnswers = 0;
                        // API returns a LinkedTreeMap
                        for (String map : ((LinkedTreeMap<String, String>) baseItem.getAnswer()).values()) {
                            if (map != null && !map.equals("null")) {
                                numAnswers++;
                            }
                        }
                        if (numAnswers == ((LinkedTreeMap<String, String>) baseItem.getAnswer()).size()) {
                            addAnsweredQuestion(questionId);
                        } else {
                            removeAnsweredQuestion(questionId);
                        }
                    }
                }
            });
        }
    }, flagStateCallback);
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) QuizPostMultipleDropdown(com.instructure.candroid.interfaces.QuizPostMultipleDropdown) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) StatusCallback(com.instructure.canvasapi2.StatusCallback) QuizSubmissionQuestion(com.instructure.canvasapi2.models.QuizSubmissionQuestion) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse) Response(retrofit2.Response) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)

Aggregations

LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)30 Gson (com.google.gson.Gson)15 ArrayList (java.util.ArrayList)10 JsonObject (com.google.gson.JsonObject)6 HashMap (java.util.HashMap)6 InputStreamReader (java.io.InputStreamReader)5 URL (java.net.URL)5 List (java.util.List)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)3 LSCustomErrorStrategy (org.ballerinalang.langserver.common.LSCustomErrorStrategy)3 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)3 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)3 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)3 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)3 NonNull (android.support.annotation.NonNull)2 Tuple2 (bisq.common.util.Tuple2)2 JsonElement (com.google.gson.JsonElement)2 StatusCallback (com.instructure.canvasapi2.StatusCallback)2