Search in sources :

Example 26 with JsonValue

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();
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Example 27 with JsonValue

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);
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) SlowOperationDTO(com.hazelcast.internal.management.dto.SlowOperationDTO)

Example 28 with JsonValue

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;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject)

Example 29 with JsonValue

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;
}
Also used : BoxJsonObject(com.box.androidsdk.content.models.BoxJsonObject) JsonValue(com.eclipsesource.json.JsonValue)

Example 30 with JsonValue

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Aggregations

JsonValue (com.eclipsesource.json.JsonValue)43 JsonObject (com.eclipsesource.json.JsonObject)19 JsonArray (com.eclipsesource.json.JsonArray)12 HashMap (java.util.HashMap)6 ParseException (com.eclipsesource.json.ParseException)4 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)3 Member (com.eclipsesource.json.JsonObject.Member)2 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)2 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 PublicKey (java.security.PublicKey)2 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Map (java.util.Map)2 EndpointContext (org.eclipse.californium.elements.EndpointContext)2 Link (org.eclipse.leshan.Link)2