use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class TestDataObjectConverter method toJson.
public static void toJson(TestDataObject obj, JsonObject json) {
if (obj.getAddedAggregatedDataObjects() != null) {
JsonArray array = new JsonArray();
obj.getAddedAggregatedDataObjects().forEach(item -> array.add(item.toJson()));
json.put("addedAggregatedDataObjects", array);
}
if (obj.getAddedBoxedBooleanValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedBoxedBooleanValues().forEach(item -> array.add(item));
json.put("addedBoxedBooleanValues", array);
}
if (obj.getAddedBoxedByteValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedBoxedByteValues().forEach(item -> array.add(item));
json.put("addedBoxedByteValues", array);
}
if (obj.getAddedBoxedCharValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedBoxedCharValues().forEach(item -> array.add(Character.toString(item)));
json.put("addedBoxedCharValues", array);
}
if (obj.getAddedBoxedDoubleValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedBoxedDoubleValues().forEach(item -> array.add(item));
json.put("addedBoxedDoubleValues", array);
}
if (obj.getAddedBoxedFloatValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedBoxedFloatValues().forEach(item -> array.add(item));
json.put("addedBoxedFloatValues", array);
}
if (obj.getAddedBoxedIntValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedBoxedIntValues().forEach(item -> array.add(item));
json.put("addedBoxedIntValues", array);
}
if (obj.getAddedBoxedLongValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedBoxedLongValues().forEach(item -> array.add(item));
json.put("addedBoxedLongValues", array);
}
if (obj.getAddedBoxedShortValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedBoxedShortValues().forEach(item -> array.add(item));
json.put("addedBoxedShortValues", array);
}
if (obj.getAddedBuffers() != null) {
JsonArray array = new JsonArray();
obj.getAddedBuffers().forEach(item -> array.add(item.getBytes()));
json.put("addedBuffers", array);
}
if (obj.getAddedHttpMethods() != null) {
JsonArray array = new JsonArray();
obj.getAddedHttpMethods().forEach(item -> array.add(item.name()));
json.put("addedHttpMethods", array);
}
if (obj.getAddedJsonArrays() != null) {
JsonArray array = new JsonArray();
obj.getAddedJsonArrays().forEach(item -> array.add(item));
json.put("addedJsonArrays", array);
}
if (obj.getAddedJsonObjects() != null) {
JsonArray array = new JsonArray();
obj.getAddedJsonObjects().forEach(item -> array.add(item));
json.put("addedJsonObjects", array);
}
if (obj.getAddedObjects() != null) {
JsonArray array = new JsonArray();
obj.getAddedObjects().forEach(item -> array.add(item));
json.put("addedObjects", array);
}
if (obj.getAddedStringValues() != null) {
JsonArray array = new JsonArray();
obj.getAddedStringValues().forEach(item -> array.add(item));
json.put("addedStringValues", array);
}
if (obj.getAggregatedDataObject() != null) {
json.put("aggregatedDataObject", obj.getAggregatedDataObject().toJson());
}
if (obj.getAggregatedDataObjectMap() != null) {
JsonObject map = new JsonObject();
obj.getAggregatedDataObjectMap().forEach((key, value) -> map.put(key, value.toJson()));
json.put("aggregatedDataObjectMap", map);
}
if (obj.getAggregatedDataObjects() != null) {
JsonArray array = new JsonArray();
obj.getAggregatedDataObjects().forEach(item -> array.add(item.toJson()));
json.put("aggregatedDataObjects", array);
}
json.put("booleanValue", obj.isBooleanValue());
if (obj.isBoxedBooleanValue() != null) {
json.put("boxedBooleanValue", obj.isBoxedBooleanValue());
}
if (obj.getBoxedBooleanValueMap() != null) {
JsonObject map = new JsonObject();
obj.getBoxedBooleanValueMap().forEach((key, value) -> map.put(key, value));
json.put("boxedBooleanValueMap", map);
}
if (obj.getBoxedBooleanValues() != null) {
JsonArray array = new JsonArray();
obj.getBoxedBooleanValues().forEach(item -> array.add(item));
json.put("boxedBooleanValues", array);
}
if (obj.getBoxedByteValue() != null) {
json.put("boxedByteValue", obj.getBoxedByteValue());
}
if (obj.getBoxedByteValueMap() != null) {
JsonObject map = new JsonObject();
obj.getBoxedByteValueMap().forEach((key, value) -> map.put(key, value));
json.put("boxedByteValueMap", map);
}
if (obj.getBoxedByteValues() != null) {
JsonArray array = new JsonArray();
obj.getBoxedByteValues().forEach(item -> array.add(item));
json.put("boxedByteValues", array);
}
if (obj.getBoxedCharValue() != null) {
json.put("boxedCharValue", Character.toString(obj.getBoxedCharValue()));
}
if (obj.getBoxedCharValueMap() != null) {
JsonObject map = new JsonObject();
obj.getBoxedCharValueMap().forEach((key, value) -> map.put(key, Character.toString(value)));
json.put("boxedCharValueMap", map);
}
if (obj.getBoxedCharValues() != null) {
JsonArray array = new JsonArray();
obj.getBoxedCharValues().forEach(item -> array.add(Character.toString(item)));
json.put("boxedCharValues", array);
}
if (obj.getBoxedDoubleValue() != null) {
json.put("boxedDoubleValue", obj.getBoxedDoubleValue());
}
if (obj.getBoxedDoubleValueMap() != null) {
JsonObject map = new JsonObject();
obj.getBoxedDoubleValueMap().forEach((key, value) -> map.put(key, value));
json.put("boxedDoubleValueMap", map);
}
if (obj.getBoxedDoubleValues() != null) {
JsonArray array = new JsonArray();
obj.getBoxedDoubleValues().forEach(item -> array.add(item));
json.put("boxedDoubleValues", array);
}
if (obj.getBoxedFloatValue() != null) {
json.put("boxedFloatValue", obj.getBoxedFloatValue());
}
if (obj.getBoxedFloatValueMap() != null) {
JsonObject map = new JsonObject();
obj.getBoxedFloatValueMap().forEach((key, value) -> map.put(key, value));
json.put("boxedFloatValueMap", map);
}
if (obj.getBoxedFloatValues() != null) {
JsonArray array = new JsonArray();
obj.getBoxedFloatValues().forEach(item -> array.add(item));
json.put("boxedFloatValues", array);
}
if (obj.getBoxedIntValue() != null) {
json.put("boxedIntValue", obj.getBoxedIntValue());
}
if (obj.getBoxedIntValueMap() != null) {
JsonObject map = new JsonObject();
obj.getBoxedIntValueMap().forEach((key, value) -> map.put(key, value));
json.put("boxedIntValueMap", map);
}
if (obj.getBoxedIntValues() != null) {
JsonArray array = new JsonArray();
obj.getBoxedIntValues().forEach(item -> array.add(item));
json.put("boxedIntValues", array);
}
if (obj.getBoxedLongValue() != null) {
json.put("boxedLongValue", obj.getBoxedLongValue());
}
if (obj.getBoxedLongValueMap() != null) {
JsonObject map = new JsonObject();
obj.getBoxedLongValueMap().forEach((key, value) -> map.put(key, value));
json.put("boxedLongValueMap", map);
}
if (obj.getBoxedLongValues() != null) {
JsonArray array = new JsonArray();
obj.getBoxedLongValues().forEach(item -> array.add(item));
json.put("boxedLongValues", array);
}
if (obj.getBoxedShortValue() != null) {
json.put("boxedShortValue", obj.getBoxedShortValue());
}
if (obj.getBoxedShortValueMap() != null) {
JsonObject map = new JsonObject();
obj.getBoxedShortValueMap().forEach((key, value) -> map.put(key, value));
json.put("boxedShortValueMap", map);
}
if (obj.getBoxedShortValues() != null) {
JsonArray array = new JsonArray();
obj.getBoxedShortValues().forEach(item -> array.add(item));
json.put("boxedShortValues", array);
}
if (obj.getBuffer() != null) {
json.put("buffer", obj.getBuffer().getBytes());
}
if (obj.getBufferMap() != null) {
JsonObject map = new JsonObject();
obj.getBufferMap().forEach((key, value) -> map.put(key, value.getBytes()));
json.put("bufferMap", map);
}
if (obj.getBuffers() != null) {
JsonArray array = new JsonArray();
obj.getBuffers().forEach(item -> array.add(item.getBytes()));
json.put("buffers", array);
}
json.put("byteValue", obj.getByteValue());
json.put("charValue", Character.toString(obj.getCharValue()));
json.put("doubleValue", obj.getDoubleValue());
json.put("floatValue", obj.getFloatValue());
if (obj.getHttpMethod() != null) {
json.put("httpMethod", obj.getHttpMethod().name());
}
if (obj.getHttpMethodMap() != null) {
JsonObject map = new JsonObject();
obj.getHttpMethodMap().forEach((key, value) -> map.put(key, value.name()));
json.put("httpMethodMap", map);
}
if (obj.getHttpMethods() != null) {
JsonArray array = new JsonArray();
obj.getHttpMethods().forEach(item -> array.add(item.name()));
json.put("httpMethods", array);
}
json.put("intValue", obj.getIntValue());
if (obj.getJsonArray() != null) {
json.put("jsonArray", obj.getJsonArray());
}
if (obj.getJsonArrayMap() != null) {
JsonObject map = new JsonObject();
obj.getJsonArrayMap().forEach((key, value) -> map.put(key, value));
json.put("jsonArrayMap", map);
}
if (obj.getJsonArrays() != null) {
JsonArray array = new JsonArray();
obj.getJsonArrays().forEach(item -> array.add(item));
json.put("jsonArrays", array);
}
if (obj.getJsonObject() != null) {
json.put("jsonObject", obj.getJsonObject());
}
if (obj.getJsonObjectMap() != null) {
JsonObject map = new JsonObject();
obj.getJsonObjectMap().forEach((key, value) -> map.put(key, value));
json.put("jsonObjectMap", map);
}
if (obj.getJsonObjects() != null) {
JsonArray array = new JsonArray();
obj.getJsonObjects().forEach(item -> array.add(item));
json.put("jsonObjects", array);
}
if (obj.getKeyedBoxedBooleanValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBoxedBooleanValues().forEach((key, value) -> map.put(key, value));
json.put("keyedBoxedBooleanValues", map);
}
if (obj.getKeyedBoxedByteValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBoxedByteValues().forEach((key, value) -> map.put(key, value));
json.put("keyedBoxedByteValues", map);
}
if (obj.getKeyedBoxedCharValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBoxedCharValues().forEach((key, value) -> map.put(key, Character.toString(value)));
json.put("keyedBoxedCharValues", map);
}
if (obj.getKeyedBoxedDoubleValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBoxedDoubleValues().forEach((key, value) -> map.put(key, value));
json.put("keyedBoxedDoubleValues", map);
}
if (obj.getKeyedBoxedFloatValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBoxedFloatValues().forEach((key, value) -> map.put(key, value));
json.put("keyedBoxedFloatValues", map);
}
if (obj.getKeyedBoxedIntValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBoxedIntValues().forEach((key, value) -> map.put(key, value));
json.put("keyedBoxedIntValues", map);
}
if (obj.getKeyedBoxedLongValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBoxedLongValues().forEach((key, value) -> map.put(key, value));
json.put("keyedBoxedLongValues", map);
}
if (obj.getKeyedBoxedShortValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBoxedShortValues().forEach((key, value) -> map.put(key, value));
json.put("keyedBoxedShortValues", map);
}
if (obj.getKeyedBufferValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedBufferValues().forEach((key, value) -> map.put(key, value.getBytes()));
json.put("keyedBufferValues", map);
}
if (obj.getKeyedDataObjectValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedDataObjectValues().forEach((key, value) -> map.put(key, value.toJson()));
json.put("keyedDataObjectValues", map);
}
if (obj.getKeyedEnumValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedEnumValues().forEach((key, value) -> map.put(key, value.name()));
json.put("keyedEnumValues", map);
}
if (obj.getKeyedJsonArrayValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedJsonArrayValues().forEach((key, value) -> map.put(key, value));
json.put("keyedJsonArrayValues", map);
}
if (obj.getKeyedJsonObjectValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedJsonObjectValues().forEach((key, value) -> map.put(key, value));
json.put("keyedJsonObjectValues", map);
}
if (obj.getKeyedObjectValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedObjectValues().forEach((key, value) -> map.put(key, value));
json.put("keyedObjectValues", map);
}
if (obj.getKeyedStringValues() != null) {
JsonObject map = new JsonObject();
obj.getKeyedStringValues().forEach((key, value) -> map.put(key, value));
json.put("keyedStringValues", map);
}
json.put("longValue", obj.getLongValue());
if (obj.getObjectMap() != null) {
JsonObject map = new JsonObject();
obj.getObjectMap().forEach((key, value) -> map.put(key, value));
json.put("objectMap", map);
}
if (obj.getObjects() != null) {
JsonArray array = new JsonArray();
obj.getObjects().forEach(item -> array.add(item));
json.put("objects", array);
}
json.put("shortValue", obj.getShortValue());
if (obj.getStringValue() != null) {
json.put("stringValue", obj.getStringValue());
}
if (obj.getStringValueMap() != null) {
JsonObject map = new JsonObject();
obj.getStringValueMap().forEach((key, value) -> map.put(key, value));
json.put("stringValueMap", map);
}
if (obj.getStringValues() != null) {
JsonArray array = new JsonArray();
obj.getStringValues().forEach(item -> array.add(item));
json.put("stringValues", array);
}
}
use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class NetTest method testClientOptionsJson.
@Test
public void testClientOptionsJson() {
int sendBufferSize = TestUtils.randomPositiveInt();
int receiverBufferSize = TestUtils.randomPortInt();
Random rand = new Random();
boolean reuseAddress = rand.nextBoolean();
int trafficClass = TestUtils.randomByte() + 128;
boolean tcpNoDelay = rand.nextBoolean();
boolean tcpKeepAlive = rand.nextBoolean();
int soLinger = TestUtils.randomPositiveInt();
boolean usePooledBuffers = rand.nextBoolean();
int idleTimeout = TestUtils.randomPositiveInt();
boolean ssl = rand.nextBoolean();
JksOptions keyStoreOptions = new JksOptions();
String ksPassword = TestUtils.randomAlphaString(100);
keyStoreOptions.setPassword(ksPassword);
String ksPath = TestUtils.randomAlphaString(100);
keyStoreOptions.setPath(ksPath);
JksOptions trustStoreOptions = new JksOptions();
String tsPassword = TestUtils.randomAlphaString(100);
trustStoreOptions.setPassword(tsPassword);
String tsPath = TestUtils.randomAlphaString(100);
trustStoreOptions.setPath(tsPath);
String enabledCipher = TestUtils.randomAlphaString(100);
int connectTimeout = TestUtils.randomPositiveInt();
boolean trustAll = rand.nextBoolean();
String crlPath = TestUtils.randomUnicodeString(100);
int reconnectAttempts = TestUtils.randomPositiveInt();
long reconnectInterval = TestUtils.randomPositiveInt();
boolean useAlpn = TestUtils.randomBoolean();
String hostnameVerificationAlgorithm = TestUtils.randomAlphaString(10);
String sslEngine = TestUtils.randomBoolean() ? "jdkSslEngineOptions" : "openSslEngineOptions";
boolean openSslSessionCacheEnabled = rand.nextBoolean();
JsonObject json = new JsonObject();
json.put("sendBufferSize", sendBufferSize).put("receiveBufferSize", receiverBufferSize).put("reuseAddress", reuseAddress).put("trafficClass", trafficClass).put("tcpNoDelay", tcpNoDelay).put("tcpKeepAlive", tcpKeepAlive).put("soLinger", soLinger).put("usePooledBuffers", usePooledBuffers).put("idleTimeout", idleTimeout).put("ssl", ssl).put("enabledCipherSuites", new JsonArray().add(enabledCipher)).put("connectTimeout", connectTimeout).put("trustAll", trustAll).put("crlPaths", new JsonArray().add(crlPath)).put("keyStoreOptions", new JsonObject().put("password", ksPassword).put("path", ksPath)).put("trustStoreOptions", new JsonObject().put("password", tsPassword).put("path", tsPath)).put("reconnectAttempts", reconnectAttempts).put("reconnectInterval", reconnectInterval).put("useAlpn", useAlpn).put(sslEngine, new JsonObject()).put("hostnameVerificationAlgorithm", hostnameVerificationAlgorithm).put("openSslSessionCacheEnabled", openSslSessionCacheEnabled);
NetClientOptions options = new NetClientOptions(json);
assertEquals(sendBufferSize, options.getSendBufferSize());
assertEquals(receiverBufferSize, options.getReceiveBufferSize());
assertEquals(reuseAddress, options.isReuseAddress());
assertEquals(trafficClass, options.getTrafficClass());
assertEquals(tcpKeepAlive, options.isTcpKeepAlive());
assertEquals(tcpNoDelay, options.isTcpNoDelay());
assertEquals(soLinger, options.getSoLinger());
assertEquals(usePooledBuffers, options.isUsePooledBuffers());
assertEquals(idleTimeout, options.getIdleTimeout());
assertEquals(ssl, options.isSsl());
assertNotSame(keyStoreOptions, options.getKeyCertOptions());
assertEquals(ksPassword, ((JksOptions) options.getKeyCertOptions()).getPassword());
assertEquals(ksPath, ((JksOptions) options.getKeyCertOptions()).getPath());
assertNotSame(trustStoreOptions, options.getTrustOptions());
assertEquals(tsPassword, ((JksOptions) options.getTrustOptions()).getPassword());
assertEquals(tsPath, ((JksOptions) options.getTrustOptions()).getPath());
assertEquals(1, options.getEnabledCipherSuites().size());
assertTrue(options.getEnabledCipherSuites().contains(enabledCipher));
assertEquals(connectTimeout, options.getConnectTimeout());
assertEquals(trustAll, options.isTrustAll());
assertEquals(1, options.getCrlPaths().size());
assertEquals(crlPath, options.getCrlPaths().get(0));
assertEquals(reconnectAttempts, options.getReconnectAttempts());
assertEquals(reconnectInterval, options.getReconnectInterval());
assertEquals(useAlpn, options.isUseAlpn());
switch(sslEngine) {
case "jdkSslEngineOptions":
assertTrue(options.getSslEngineOptions() instanceof JdkSSLEngineOptions);
break;
case "openSslEngineOptions":
assertTrue(options.getSslEngineOptions() instanceof OpenSSLEngineOptions);
break;
default:
fail();
break;
}
assertEquals(hostnameVerificationAlgorithm, options.getHostnameVerificationAlgorithm());
// Test other keystore/truststore types
json.remove("keyStoreOptions");
json.remove("trustStoreOptions");
json.put("pfxKeyCertOptions", new JsonObject().put("password", ksPassword)).put("pfxTrustOptions", new JsonObject().put("password", tsPassword));
options = new NetClientOptions(json);
assertTrue(options.getTrustOptions() instanceof PfxOptions);
assertTrue(options.getKeyCertOptions() instanceof PfxOptions);
json.remove("pfxKeyCertOptions");
json.remove("pfxTrustOptions");
json.put("pemKeyCertOptions", new JsonObject()).put("pemTrustOptions", new JsonObject());
options = new NetClientOptions(json);
assertTrue(options.getTrustOptions() instanceof PemTrustOptions);
assertTrue(options.getKeyCertOptions() instanceof PemKeyCertOptions);
}
use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class DeploymentOptions method fromJson.
/**
* Initialise the fields of this instance from the specified JSON
*
* @param json the JSON
*/
public void fromJson(JsonObject json) {
this.config = json.getJsonObject("config");
this.worker = json.getBoolean("worker", DEFAULT_WORKER);
this.multiThreaded = json.getBoolean("multiThreaded", DEFAULT_MULTI_THREADED);
this.isolationGroup = json.getString("isolationGroup", DEFAULT_ISOLATION_GROUP);
this.ha = json.getBoolean("ha", DEFAULT_HA);
JsonArray arr = json.getJsonArray("extraClasspath", null);
if (arr != null) {
this.extraClasspath = arr.getList();
}
this.instances = json.getInteger("instances", DEFAULT_INSTANCES);
JsonArray arrIsolated = json.getJsonArray("isolatedClasses", null);
if (arrIsolated != null) {
this.isolatedClasses = arrIsolated.getList();
}
}
use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class EventBusTestBase method testSendJsonArray.
@Test
public void testSendJsonArray() {
JsonArray arr = new JsonArray();
arr.add(TestUtils.randomUnicodeString(100)).add(TestUtils.randomInt()).add(TestUtils.randomBoolean());
testSend(arr, (received) -> {
assertEquals(arr, received);
// Make sure it's copied
assertFalse(arr == received);
});
}
use of io.vertx.core.json.JsonArray in project vert.x by eclipse.
the class EventBusTestBase method testPublishJsonArray.
@Test
public void testPublishJsonArray() {
JsonArray arr = new JsonArray();
arr.add(TestUtils.randomUnicodeString(100)).add(TestUtils.randomInt()).add(TestUtils.randomBoolean());
testPublish(arr, (received) -> {
assertEquals(arr, received);
// Make sure it's copied
assertFalse(arr == received);
});
}
Aggregations