Search in sources :

Example 6 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class ClientEndPointDTO method toJson.

@Override
public JsonObject toJson() {
    final JsonObject root = Json.object();
    root.add("uuid", uuid.toString());
    root.add("address", address);
    root.add("clientType", clientType);
    root.add("name", name);
    JsonArray labelsObject = Json.array();
    for (String label : labels) {
        labelsObject.add(label);
    }
    root.add("labels", labelsObject);
    root.add("ipAddress", ipAddress);
    root.add("canonicalHostName", canonicalHostName);
    return root;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject) JsonUtil.getString(com.hazelcast.internal.util.JsonUtil.getString)

Example 7 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class ClientEndPointDTO method fromJson.

@Override
public void fromJson(JsonObject json) {
    uuid = UUID.fromString(getString(json, "uuid"));
    address = getString(json, "address");
    clientType = getString(json, "clientType");
    name = getString(json, "name");
    JsonArray labelsArray = getArray(json, "labels");
    labels = new HashSet<>();
    for (JsonValue labelValue : labelsArray) {
        labels.add(labelValue.asString());
    }
    ipAddress = getString(json, "ipAddress", null);
    canonicalHostName = getString(json, "canonicalHostName", null);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue)

Example 8 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class WanReplicationConfigDTO method toJson.

@Override
public JsonObject toJson() {
    JsonObject root = new JsonObject();
    if (config.getName() != null) {
        root.add("name", config.getName());
    }
    JsonArray batchPublishers = new JsonArray();
    JsonArray customPublishers = new JsonArray();
    for (WanBatchPublisherConfig publisherConfig : config.getBatchPublisherConfigs()) {
        batchPublishers.add(new WanBatchPublisherConfigDTO(publisherConfig).toJson());
    }
    for (WanCustomPublisherConfig publisherConfig : config.getCustomPublisherConfigs()) {
        customPublishers.add(new CustomWanPublisherConfigDTO(publisherConfig).toJson());
    }
    root.add("batchPublishers", batchPublishers);
    root.add("customPublishers", customPublishers);
    WanConsumerConfig consumerConfig = config.getConsumerConfig();
    if (consumerConfig != null) {
        root.add("consumer", new WanConsumerConfigDTO(consumerConfig).toJson());
    }
    return root;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) WanBatchPublisherConfig(com.hazelcast.config.WanBatchPublisherConfig) WanConsumerConfig(com.hazelcast.config.WanConsumerConfig) WanCustomPublisherConfig(com.hazelcast.config.WanCustomPublisherConfig) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 9 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class EventBatch method toJson.

public JsonObject toJson() {
    JsonObject json = new JsonObject();
    json.add("cluster", cluster);
    json.add("address", address);
    JsonArray eventJsonArray = new JsonArray();
    for (Event event : events) {
        JsonObject metadataJson = new JsonObject();
        metadataJson.add("type", event.getType().getCode());
        metadataJson.add("timestamp", event.getTimestamp());
        JsonObject eventJson = new JsonObject();
        eventJson.add("metadata", metadataJson);
        eventJson.add("data", event.toJson());
        eventJsonArray.add(eventJson);
    }
    json.add("events", eventJsonArray);
    return json;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 10 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class PermissionConfigDTO method toJson.

@Override
public JsonObject toJson() {
    JsonObject object = new JsonObject();
    object.add("permissionType", permissionConfig.getType().getNodeName());
    object.add("name", permissionConfig.getName());
    if (StringUtil.isNullOrEmptyAfterTrim(permissionConfig.getPrincipal())) {
        object.add("principal", "*");
    } else {
        object.add("principal", permissionConfig.getPrincipal());
    }
    Set<String> endpoints = permissionConfig.getEndpoints();
    if (endpoints != null) {
        JsonArray endpointsArray = new JsonArray();
        for (String endpoint : endpoints) {
            endpointsArray.add(endpoint);
        }
        object.add("endpoints", endpointsArray);
    }
    Set<String> actions = permissionConfig.getActions();
    if (actions != null) {
        JsonArray actionsArray = new JsonArray();
        for (String action : actions) {
            actionsArray.add(action);
        }
        object.add("actions", actionsArray);
    }
    return object;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject)

Aggregations

JsonArray (com.hazelcast.internal.json.JsonArray)74 JsonObject (com.hazelcast.internal.json.JsonObject)42 Test (org.junit.Test)39 QuickTest (com.hazelcast.test.annotation.QuickTest)31 JsonValue (com.hazelcast.internal.json.JsonValue)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 CPMember (com.hazelcast.cp.CPMember)7 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 Address (com.hazelcast.cluster.Address)3 JetException (com.hazelcast.jet.JetException)3 InputStreamReader (java.io.InputStreamReader)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Request (org.elasticsearch.client.Request)3