use of elemental.json.JsonValue in project che by eclipse.
the class JsonRpcParamsTest method shouldToJsonForCreatedSingleBooleanParams.
@Test
public void shouldToJsonForCreatedSingleBooleanParams() throws Exception {
Boolean expected = false;
JsonRpcParams jsonRpcParams = new JsonRpcParams(expected, dtoFactory, jsonFactory);
JsonValue actual = jsonRpcParams.toJsonValue();
assertEquals(expected, Boolean.valueOf(actual.toJson()));
}
use of elemental.json.JsonValue in project che by eclipse.
the class JsonRpcParamsTest method shouldToJsonForCreatedSingleDoubleParams.
@Test
public void shouldToJsonForCreatedSingleDoubleParams() throws Exception {
Double expected = 0D;
JsonRpcParams jsonRpcParams = new JsonRpcParams(expected, dtoFactory, jsonFactory);
JsonValue actual = jsonRpcParams.toJsonValue();
assertEquals(expected, Double.valueOf(actual.toJson()));
}
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));
}
Aggregations