use of com.eclipsesource.json.JsonValue in project hazelcast by hazelcast.
the class JsonUtil method getString.
/**
* Returns a field in a Json object as a string.
* Throws IllegalArgumentException if the field value is null.
*
* @param object the Json Object
* @param field the field in the Json object to return
* @return the Json field value as a string
*/
public static String getString(JsonObject object, String field) {
final JsonValue value = object.get(field);
throwExceptionIfNull(value, field);
return value.asString();
}
use of com.eclipsesource.json.JsonValue in project hazelcast by hazelcast.
the class LocalOperationStatsImpl method fromJson.
@Override
public void fromJson(JsonObject json) {
maxVisibleSlowOperationCount = getLong(json, "maxVisibleSlowOperationCount", Long.MAX_VALUE);
for (JsonValue jsonValue : getArray(json, "slowOperations")) {
SlowOperationDTO slowOperationDTO = new SlowOperationDTO();
slowOperationDTO.fromJson(jsonValue.asObject());
slowOperations.add(slowOperationDTO);
}
creationTime = getLong(json, "creationTime", -1L);
}
use of com.eclipsesource.json.JsonValue in project box-android-sdk by box.
the class BoxItem method parsePathCollection.
private List<BoxFolder> parsePathCollection(JsonObject jsonObject) {
int count = jsonObject.get("total_count").asInt();
List<BoxFolder> pathCollection = new ArrayList<BoxFolder>(count);
JsonArray entries = jsonObject.get("entries").asArray();
for (JsonValue value : entries) {
JsonObject entry = value.asObject();
BoxFolder folder = new BoxFolder();
folder.createFromJson(entry);
pathCollection.add(folder);
}
return pathCollection;
}
use of com.eclipsesource.json.JsonValue in project box-android-sdk by box.
the class BoxRequest method parseJsonObject.
protected JsonValue parseJsonObject(Object obj) {
String json = ((BoxJsonObject) obj).toJson();
JsonValue value = JsonValue.readFrom(json);
return value;
}
use of com.eclipsesource.json.JsonValue in project universa by UniversaBlockchain.
the class JsonTool method fromJson.
public static <T> T fromJson(JsonValue jsonValue) {
if (jsonValue.isNumber()) {
double real = jsonValue.asDouble();
return real != (int) real ? (T) Double.valueOf(real) : (T) Long.valueOf((long) real);
}
if (jsonValue.isString())
return (T) jsonValue.asString();
if (jsonValue.isNull())
return null;
if (jsonValue.isTrue())
return (T) Boolean.TRUE;
if (jsonValue.isFalse())
return (T) Boolean.FALSE;
if (jsonValue.isObject()) {
JsonObject jo = (JsonObject) jsonValue;
HashMap<String, Object> result = new HashMap<>();
for (JsonObject.Member m : jo) {
result.put(m.getName(), fromJson(m.getValue()));
}
return (T) result;
}
if (jsonValue.isArray()) {
JsonArray array = (JsonArray) jsonValue;
ArrayList<Object> result = new ArrayList<>(array.size());
for (JsonValue value : array) {
result.add(fromJson(value));
}
return (T) result;
}
throw new IllegalArgumentException("cant convert this type of value: " + jsonValue);
}
Aggregations