Search in sources :

Example 26 with JsonValue

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()));
}
Also used : JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 27 with JsonValue

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()));
}
Also used : JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 28 with JsonValue

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;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(elemental.json.JsonValue)

Example 29 with JsonValue

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;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(elemental.json.JsonValue)

Example 30 with JsonValue

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));
}
Also used : JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Aggregations

JsonValue (elemental.json.JsonValue)55 Test (org.junit.Test)52 JsonArray (elemental.json.JsonArray)23 JsonObject (elemental.json.JsonObject)19 JsonString (elemental.json.JsonString)10 Matchers.anyString (org.mockito.Matchers.anyString)5 JsonNumber (elemental.json.JsonNumber)3 ArrayList (java.util.ArrayList)2