List of usage examples for com.google.gson JsonObject keySet
public Set<String> keySet()
From source file:com.keydap.sparrow.PatchGenerator.java
License:Apache License
private void diffNonNullObjects(PatchRequest pr, String path, Object modified, Object original) throws Exception { Class cls = modified.getClass(); boolean pt = isPrimitive(cls); if (pt) {/* w w w . ja v a 2s . c o m*/ if (modified.equals(original)) { return; } updatePr("replace", pr, path, modified); return; } // construct path like ims[type=\"home\"] path = buildPathWithFilter(path, original); JsonObject obj = new JsonObject(); for (Field f : getFields(cls)) { Object m = f.get(modified); Object o = f.get(original); String name = f.getName(); if (m == o) { continue; } else if ((m != null) && (o == null)) { obj.add(name, serializer.toJsonTree(m)); } else if ((m == null) && (o != null)) { // do nothing } else if (!m.equals(o)) { obj.add(name, serializer.toJsonTree(m)); } } if (!obj.keySet().isEmpty()) { updatePr("replace", pr, path, obj); } }
From source file:com.keydap.sparrow.SparrowClient.java
License:Apache License
private JsonObject keysToLower(JsonObject obj) { JsonObject tmp = new JsonObject(); for (String key : obj.keySet()) { JsonElement je = obj.get(key);//from w ww .j a v a 2 s.c o m if (key.contains(":")) { JsonObject ext = keysToLower((JsonObject) je); tmp.add(key, ext); } else { if (je.isJsonObject()) { je = keysToLower((JsonObject) je); } else if (je.isJsonArray()) { JsonArray arr = je.getAsJsonArray(); for (int i = 0; i < arr.size(); i++) { JsonElement item = arr.get(i); if (item.isJsonObject()) { item = keysToLower((JsonObject) item); arr.set(i, item); } } } tmp.add(key.toLowerCase(), je); } } return tmp; }
From source file:org.apache.mxnetexamples.javaapi.infer.bert.BertDataParser.java
License:Apache License
/** * Parse the Vocabulary to JSON files//from ww w . j a v a2 s . com * [PAD], [CLS], [SEP], [MASK], [UNK] are reserved tokens * @param jsonFile the filePath of the vocab.json * @throws Exception */ void parseJSON(String jsonFile) throws Exception { Gson gson = new Gson(); token2idx = new HashMap<>(); idx2token = new LinkedList<>(); JsonObject jsonObject = gson.fromJson(new FileReader(jsonFile), JsonObject.class); JsonArray arr = jsonObject.getAsJsonArray("idx_to_token"); for (JsonElement element : arr) { idx2token.add(element.getAsString()); } JsonObject preMap = jsonObject.getAsJsonObject("token_to_idx"); for (String key : preMap.keySet()) { token2idx.put(key, preMap.get(key).getAsInt()); } }