use of elemental.json.JsonValue in project flow by vaadin.
the class JsonUtilsTest method testStream.
@Test
public void testStream() {
JsonArray array = createTestArray1();
List<JsonValue> list = JsonUtils.stream(array).collect(Collectors.toList());
Assert.assertEquals(2, list.size());
Assert.assertEquals("foo", list.get(0).asString());
Assert.assertTrue(JsonUtils.jsonEquals(list.get(1), Json.createObject()));
}
use of elemental.json.JsonValue in project che by eclipse.
the class JsonRpcParams method getAsListOf.
public <T> List<T> getAsListOf(Class<T> type) {
checkNotNull(type, "Type must not be null");
List<T> list = new ArrayList<>(paramsList.size());
for (int i = 0; i < paramsList.size(); i++) {
JsonValue jsonValue = paramsList.get(i);
T item;
if (type.equals(String.class)) {
item = (T) jsonValue.asString();
} else if (type.equals(Double.class)) {
Double d = jsonValue.asNumber();
item = (T) d;
} else if (type.equals(Boolean.class)) {
Boolean b = jsonValue.asBoolean();
item = (T) b;
} else {
item = dtoFactory.createDtoFromJson(jsonValue.toJson(), type);
}
list.add(i, item);
}
return list;
}
use of elemental.json.JsonValue in project che by eclipse.
the class JsonRpcResult method getAsListOf.
public <T> List<T> getAsListOf(Class<T> type) {
List<T> list = new ArrayList<>(resultList.size());
for (int i = 0; i < resultList.size(); i++) {
JsonValue jsonValue = resultList.get(i);
T item;
if (type.equals(String.class)) {
item = (T) jsonValue.asString();
} else if (type.equals(Double.class)) {
item = (T) (Double) jsonValue.asNumber();
} else if (type.equals(Boolean.class)) {
item = (T) (Boolean) jsonValue.asBoolean();
} else {
item = dtoFactory.createDtoFromJson(jsonValue.toJson(), type);
}
list.add(i, item);
}
return list;
}
use of elemental.json.JsonValue in project che by eclipse.
the class JsonRpcErrorTest method shouldToJsonObjectProperly.
@Test
public void shouldToJsonObjectProperly() {
JsonRpcError real = new JsonRpcError(ERROR_JSON, jsonFactory);
JsonValue expected = jsonFactory.parse(ERROR_JSON);
assertTrue(real.toJsonObject().jsEquals(expected));
}
use of elemental.json.JsonValue in project che by eclipse.
the class JsonRpcListTest method shouldToJsonArrayCreatedDtoArray.
@Test
public void shouldToJsonArrayCreatedDtoArray() throws Exception {
Dto dto = mock(Dto.class);
when(dto.toString()).thenReturn(DTO);
when(dto.getParameter()).thenReturn("value");
when(dtoFactory.createDtoFromJson(DTO, Dto.class)).thenReturn(dto);
JsonArray expected = jsonFactory.createArray();
JsonValue parse = jsonFactory.parse(dto.toString());
expected.set(0, parse);
JsonRpcList jsonRpcList = new JsonRpcList(singletonList(dto), jsonFactory, dtoFactory);
JsonArray actual = jsonRpcList.toJsonArray();
assertTrue(expected.jsEquals(actual));
}
Aggregations