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"));
}
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);
}
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);
}
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);
}
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());
}
Aggregations