Search in sources :

Example 11 with JsonArray

use of io.vertx.core.json.JsonArray in project vert.x by eclipse.

the class ConversionHelperTest method testFromJsonObject.

@Test
public void testFromJsonObject() {
    JsonObject object = new JsonObject();
    object.put("string", "the_string");
    object.put("integer", 4);
    object.put("boolean", true);
    object.put("binary", "hello".getBytes());
    object.put("object", new JsonObject().put("nested", 4));
    object.put("array", new JsonArray().add(1).add(2).add(3));
    Map<String, Object> map = ConversionHelper.fromObject(object);
    assertEquals(6, map.size());
    assertEquals("the_string", map.get("string"));
    assertEquals(4, map.get("integer"));
    assertEquals(true, map.get("boolean"));
    assertEquals("hello", new String(Base64.getDecoder().decode((String) map.get("binary"))));
    assertEquals(Collections.singletonMap("nested", 4), map.get("object"));
    assertEquals(Arrays.asList(1, 2, 3), map.get("array"));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 12 with JsonArray

use of io.vertx.core.json.JsonArray in project vert.x by eclipse.

the class Examples method example3.

public void example3() {
    JsonArray array = new JsonArray();
    array.add("foo").add(123).add(false);
}
Also used : JsonArray(io.vertx.core.json.JsonArray)

Example 13 with JsonArray

use of io.vertx.core.json.JsonArray in project vert.x by eclipse.

the class HttpServerOptionsConverter method toJson.

public static void toJson(HttpServerOptions obj, JsonObject json) {
    json.put("acceptUnmaskedFrames", obj.isAcceptUnmaskedFrames());
    if (obj.getAlpnVersions() != null) {
        JsonArray array = new JsonArray();
        obj.getAlpnVersions().forEach(item -> array.add(item.name()));
        json.put("alpnVersions", array);
    }
    json.put("compressionLevel", obj.getCompressionLevel());
    json.put("compressionSupported", obj.isCompressionSupported());
    json.put("decompressionSupported", obj.isDecompressionSupported());
    json.put("handle100ContinueAutomatically", obj.isHandle100ContinueAutomatically());
    json.put("http2ConnectionWindowSize", obj.getHttp2ConnectionWindowSize());
    if (obj.getInitialSettings() != null) {
        json.put("initialSettings", obj.getInitialSettings().toJson());
    }
    json.put("maxChunkSize", obj.getMaxChunkSize());
    json.put("maxHeaderSize", obj.getMaxHeaderSize());
    json.put("maxInitialLineLength", obj.getMaxInitialLineLength());
    json.put("maxWebsocketFrameSize", obj.getMaxWebsocketFrameSize());
    json.put("maxWebsocketMessageSize", obj.getMaxWebsocketMessageSize());
    if (obj.getWebsocketSubProtocols() != null) {
        json.put("websocketSubProtocols", obj.getWebsocketSubProtocols());
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray)

Example 14 with JsonArray

use of io.vertx.core.json.JsonArray in project vert.x by eclipse.

the class Examples method example0_2.

public void example0_2() {
    String jsonString = "[\"foo\",\"bar\"]";
    JsonArray array = new JsonArray(jsonString);
}
Also used : JsonArray(io.vertx.core.json.JsonArray)

Example 15 with JsonArray

use of io.vertx.core.json.JsonArray in project vert.x by eclipse.

the class DeploymentOptionsConverter method toJson.

public static void toJson(DeploymentOptions obj, JsonObject json) {
    if (obj.getConfig() != null) {
        json.put("config", obj.getConfig());
    }
    if (obj.getExtraClasspath() != null) {
        JsonArray array = new JsonArray();
        obj.getExtraClasspath().forEach(item -> array.add(item));
        json.put("extraClasspath", array);
    }
    json.put("ha", obj.isHa());
    json.put("instances", obj.getInstances());
    if (obj.getIsolatedClasses() != null) {
        JsonArray array = new JsonArray();
        obj.getIsolatedClasses().forEach(item -> array.add(item));
        json.put("isolatedClasses", array);
    }
    if (obj.getIsolationGroup() != null) {
        json.put("isolationGroup", obj.getIsolationGroup());
    }
    json.put("maxWorkerExecuteTime", obj.getMaxWorkerExecuteTime());
    json.put("multiThreaded", obj.isMultiThreaded());
    json.put("worker", obj.isWorker());
    if (obj.getWorkerPoolName() != null) {
        json.put("workerPoolName", obj.getWorkerPoolName());
    }
    json.put("workerPoolSize", obj.getWorkerPoolSize());
}
Also used : JsonArray(io.vertx.core.json.JsonArray)

Aggregations

JsonArray (io.vertx.core.json.JsonArray)78 Test (org.junit.Test)61 JsonObject (io.vertx.core.json.JsonObject)51 ArrayList (java.util.ArrayList)15 Instant (java.time.Instant)7 HashMap (java.util.HashMap)7 AsciiString (io.netty.util.AsciiString)5 Buffer (io.vertx.core.buffer.Buffer)5 Message (io.vertx.core.eventbus.Message)3 HttpMethod (io.vertx.core.http.HttpMethod)2 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 ReplyException (io.vertx.core.eventbus.ReplyException)1 DecodeException (io.vertx.core.json.DecodeException)1 PemTrustOptions (io.vertx.core.net.PemTrustOptions)1 LocalMap (io.vertx.core.shareddata.LocalMap)1 ByteBuffer (java.nio.ByteBuffer)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1