Search in sources :

Example 36 with JsonObject

use of io.vertx.core.json.JsonObject 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 37 with JsonObject

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

the class CoreExamples method example13.

public void example13(Vertx vertx) {
    JsonObject config = new JsonObject().put("name", "tim").put("directory", "/blah");
    DeploymentOptions options = new DeploymentOptions().setConfig(config);
    vertx.deployVerticle("com.mycompany.MyOrderProcessorVerticle", options);
}
Also used : JsonObject(io.vertx.core.json.JsonObject)

Example 38 with JsonObject

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

the class Examples method mapFromPojo.

public void mapFromPojo(HttpServerRequest request) {
    User user = new User("Dale", "Cooper");
    JsonObject jsonObject = JsonObject.mapFrom(user);
}
Also used : JsonObject(io.vertx.core.json.JsonObject)

Example 39 with JsonObject

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

the class Examples method example0_1.

public void example0_1() {
    String jsonString = "{\"foo\":\"bar\"}";
    JsonObject object = new JsonObject(jsonString);
}
Also used : JsonObject(io.vertx.core.json.JsonObject)

Example 40 with JsonObject

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

the class DataObjectTest method testEmptyJsonToDataObject.

@Test
public void testEmptyJsonToDataObject() {
    JsonObject json = new JsonObject();
    TestDataObject obj = new TestDataObject();
    TestDataObjectConverter.fromJson(json, obj);
    assertEquals(null, obj.getStringValue());
    assertEquals(false, obj.isBooleanValue());
    assertEquals(0, obj.getByteValue());
    assertEquals(0, obj.getShortValue());
    assertEquals(0, obj.getIntValue());
    assertEquals(0l, obj.getLongValue());
    assertEquals(0f, obj.getFloatValue(), 0);
    assertEquals(0d, obj.getDoubleValue(), 0);
    assertEquals((char) 0, obj.getCharValue());
    assertEquals(null, obj.isBoxedBooleanValue());
    assertEquals(null, obj.getBoxedByteValue());
    assertEquals(null, obj.getBoxedShortValue());
    assertEquals(null, obj.getBoxedIntValue());
    assertEquals(null, obj.getBoxedLongValue());
    assertEquals(null, obj.getBoxedFloatValue());
    assertEquals(null, obj.getBoxedDoubleValue());
    assertEquals(null, obj.getBoxedCharValue());
    assertEquals(null, obj.getAggregatedDataObject());
    assertEquals(null, obj.getBuffer());
    assertEquals(null, obj.getJsonObject());
    assertEquals(null, obj.getJsonArray());
    assertEquals(null, obj.getStringValues());
    assertEquals(null, obj.getBoxedBooleanValues());
    assertEquals(null, obj.getBoxedByteValues());
    assertEquals(null, obj.getBoxedShortValues());
    assertEquals(null, obj.getBoxedIntValues());
    assertEquals(null, obj.getBoxedLongValues());
    assertEquals(null, obj.getBoxedFloatValues());
    assertEquals(null, obj.getBoxedDoubleValues());
    assertEquals(null, obj.getBoxedCharValues());
    assertEquals(null, obj.getAggregatedDataObjects());
    assertEquals(null, obj.getBuffers());
    assertEquals(null, obj.getJsonObjects());
    assertEquals(null, obj.getJsonArrays());
    assertEquals(null, obj.getHttpMethods());
    assertEquals(null, obj.getObjects());
    assertEquals(Collections.emptyList(), obj.getAddedStringValues());
    assertEquals(Collections.emptyList(), obj.getAddedBoxedBooleanValues());
    assertEquals(Collections.emptyList(), obj.getAddedBoxedByteValues());
    assertEquals(Collections.emptyList(), obj.getAddedBoxedShortValues());
    assertEquals(Collections.emptyList(), obj.getAddedBoxedIntValues());
    assertEquals(Collections.emptyList(), obj.getAddedBoxedLongValues());
    assertEquals(Collections.emptyList(), obj.getAddedBoxedFloatValues());
    assertEquals(Collections.emptyList(), obj.getAddedBoxedDoubleValues());
    assertEquals(Collections.emptyList(), obj.getAddedBoxedCharValues());
    assertEquals(Collections.emptyList(), obj.getAddedAggregatedDataObjects());
    assertEquals(Collections.emptyList(), obj.getAddedBuffers());
    assertEquals(Collections.emptyList(), obj.getAddedJsonObjects());
    assertEquals(Collections.emptyList(), obj.getAddedJsonArrays());
    assertEquals(Collections.emptyList(), obj.getAddedHttpMethods());
    assertEquals(Collections.emptyList(), obj.getAddedObjects());
    assertEquals(null, obj.getStringValueMap());
    assertEquals(null, obj.getBoxedBooleanValueMap());
    assertEquals(null, obj.getBoxedByteValueMap());
    assertEquals(null, obj.getBoxedShortValueMap());
    assertEquals(null, obj.getBoxedIntValueMap());
    assertEquals(null, obj.getBoxedLongValueMap());
    assertEquals(null, obj.getBoxedFloatValueMap());
    assertEquals(null, obj.getBoxedDoubleValueMap());
    assertEquals(null, obj.getBoxedCharValueMap());
    assertEquals(null, obj.getAggregatedDataObjectMap());
    assertEquals(null, obj.getBufferMap());
    assertEquals(null, obj.getJsonObjectMap());
    assertEquals(null, obj.getJsonArrayMap());
    assertEquals(null, obj.getHttpMethodMap());
    assertEquals(null, obj.getObjectMap());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)383 Test (org.junit.Test)210 JsonArray (io.vertx.core.json.JsonArray)89 HttpURLConnection (java.net.HttpURLConnection)68 Future (io.vertx.core.Future)55 Handler (io.vertx.core.Handler)51 Async (io.vertx.ext.unit.Async)50 Vertx (io.vertx.core.Vertx)48 TestContext (io.vertx.ext.unit.TestContext)48 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)47 RunWith (org.junit.runner.RunWith)47 Timeout (org.junit.rules.Timeout)43 Before (org.junit.Before)41 Rule (org.junit.Rule)33 EventBusMessage (org.eclipse.hono.util.EventBusMessage)27 AsyncResult (io.vertx.core.AsyncResult)26 Buffer (io.vertx.core.buffer.Buffer)26 Constants (org.eclipse.hono.util.Constants)25 Mockito (org.mockito.Mockito)25 Objects (java.util.Objects)23