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;
}
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;
}
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();
}
}
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;
}
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);
}
Aggregations