public static Map<String, String> readJsonProperties(String jsonString) { Map<String, String> properties = new HashMap<>(); if (jsonString != null) { JsonUtil.readJsonObject(jsonString).forEach((k, v) -> properties.put(k, v.toString())); } return properties; }
public static Map<String, Set<CandidatePhrase>> readSeedWordsFromJSONString(String str){ Map<String, Set<CandidatePhrase>> seedWords = new HashMap<>(); JsonReader jsonReader = Json.createReader(new StringReader(str)); JsonObject obj = jsonReader.readObject(); jsonReader.close(); for (String o : obj.keySet()){ seedWords.put(o, new HashSet<>()); JsonArray arr = obj.getJsonArray(o); for(JsonValue v: arr) seedWords.get(o).add(CandidatePhrase.createOrGet(v.toString())); } return seedWords; }
/** * Transform from json to object. * * @param jsonValue json value * @return object most correct for the type, or string value if not understood (e.g. json object) */ public static Object toObject(JsonValue jsonValue) { switch (jsonValue.getValueType()) { case ARRAY: return jsonValue.toString(); case OBJECT: return jsonValue.toString(); case STRING: return ((JsonString) jsonValue).getString(); case NUMBER: return ((JsonNumber) jsonValue).numberValue(); case TRUE: return true; case FALSE: return false; case NULL: return null; default: return jsonValue.toString(); } }
private int changeAnnotation(String line, boolean remove){ int tokensNum = 0; JsonReader jsonReader = Json.createReader(new StringReader(line)); JsonObject objarr = jsonReader.readObject(); for(String label: objarr.keySet()) { JsonObject obj4label = objarr.getJsonObject(label); for(String sentid: obj4label.keySet()){ JsonArray tokenArry = obj4label.getJsonArray(sentid); for(JsonValue tokenid: tokenArry){ tokensNum ++; Data.sents.get(sentid).getTokens().get(Integer.parseInt(tokenid.toString())).set(humanLabelClasses.get(label), remove ? backgroundSymbol: label); } } } return tokensNum; }
private static String asString(JsonValue value) { if (JsonValue.ValueType.STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } return value.toString(); } }
private Object convert(Claims claims, JsonValue value) { Class<?> claimClass = claims.getType(); if (claimClass.equals(String.class)) { if (value instanceof JsonString) { return ((JsonString) value).getString(); } } if (claimClass.equals(Long.class)) { if (value instanceof JsonNumber) { return ((JsonNumber) value).longValue(); } else if (value instanceof JsonString) { return Long.parseLong(((JsonString) value).getString()); } return Long.parseLong(value.toString()); } if (claimClass.equals(JsonObject.class)) { return value; } if (value instanceof JsonString) { return ((JsonString) value).getString(); } return value; }
private List<Speaker> extractSpeakerList(JsonObject talkObject, String code, String title) { List<Speaker> speakerList = new ArrayList<>(); String mainSpeakerName = talkObject.getString("mainSpeaker"); if (Arrays.asList(IGNORED_SPEAKER_NAMES).contains(mainSpeakerName)) { return speakerList; } speakerList.add(getSpeakerOrCreateOneIfNull(code, title, mainSpeakerName)); if (talkObject.containsKey("secondarySpeaker")) { String secondarySpeakerName = talkObject.getString("secondarySpeaker"); speakerList.add(getSpeakerOrCreateOneIfNull(code, title, secondarySpeakerName)); } if (talkObject.containsKey("otherSpeakers")) { JsonArray otherSpeakersArray = talkObject.getJsonArray("otherSpeakers"); for (JsonValue otherSpeakerName : otherSpeakersArray) { speakerList.add(getSpeakerOrCreateOneIfNull(code, title, otherSpeakerName.toString().replaceAll("\"", ""))); } } return speakerList; }
case TEST: if (! getValue(operation).equals(pointer.getValue(target))) { throw new JsonException(JsonMessages.PATCH_TEST_FAILED(operation.getString("path"), getValue(operation).toString()));
private static String getJsonValueAsNumberString(JsonValue value) { return (value != null && value.getValueType() == ValueType.NUMBER) ? value.toString() : null; }
private static long getJsonLong(JsonObject obj, String prop) throws ChaincodeCollectionConfigurationException { JsonValue ret = obj.get(prop); if (ret == null) { throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop)); } if (ret.getValueType() != JsonValue.ValueType.NUMBER) { throw new ChaincodeCollectionConfigurationException(format("property %s wrong type expected number got %s", prop, ret.getValueType().name())); } return Long.parseLong(ret.toString()); }
private static int getJsonInt(JsonObject obj, String prop) throws ChaincodeCollectionConfigurationException { JsonValue ret = obj.get(prop); if (ret == null) { throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop)); } if (ret.getValueType() != JsonValue.ValueType.NUMBER) { throw new ChaincodeCollectionConfigurationException(format("property %s wrong type expected number got %s", prop, ret.getValueType().name())); } return Integer.parseInt(ret.toString()); }
private static void setPeerRole(String channelName, PeerOptions peerOptions, JsonObject jsonPeer, PeerRole role) throws NetworkConfigurationException { String propName = roleNameRemap(role); JsonValue val = jsonPeer.get(propName); if (val != null) { Boolean isSet = getJsonValueAsBoolean(val); if (isSet == null) { // This is an invalid boolean value throw new NetworkConfigurationException(format("Error constructing channel %s. Role %s has invalid boolean value: %s", channelName, propName, val.toString())); } if (isSet) { peerOptions.addPeerRole(role); } } }
case TEST: if (! getValue(operation).equals(pointer.getValue(target))) { throw new JsonException(JsonMessages.PATCH_TEST_FAILED(operation.getString("path"), getValue(operation).toString()));
public static Map<String, String> readJsonProperties(String jsonString) { Map<String, String> properties = new HashMap<>(); if (jsonString != null) { JsonUtil.readJsonObject(jsonString).forEach((k, v) -> properties.put(k, v.toString())); } return properties; }
public static Map<String, String> readJsonProperties(String jsonString) { Map<String, String> properties = new HashMap<>(); if (jsonString != null) { JsonUtil.readJsonObject(jsonString).forEach((k, v) -> properties.put(k, v.toString())); } return properties; }
public static Map<String, String> readJsonProperties(String jsonString) { Map<String, String> properties = new HashMap<>(); if (jsonString != null) { JsonUtil.readJsonObject(jsonString).forEach((k, v) -> properties.put(k, v.toString())); } return properties; }
public static Map<String, String> readJsonProperties(String jsonString) { Map<String, String> properties = new HashMap<>(); if (jsonString != null) { JsonUtil.readJsonObject(jsonString).forEach((k, v) -> properties.put(k, v.toString())); } return properties; }
private String jsonValueToString(JsonValue jv) { switch ( jv.getValueType() ) { case STRING: return ((JsonString)jv).getString(); default: return jv.toString(); } }
private static String asString(JsonValue value) { if (JsonValue.ValueType.STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } return value.toString(); } }
private static String asString(JsonValue value) { if (JsonValue.ValueType.STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } return value.toString(); } }