Search in sources :

Example 56 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcParams method toJsonElement.

public JsonElement toJsonElement() {
    if (params != null) {
        return params;
    }
    JsonArray array = new JsonArray();
    paramsList.forEach(array::add);
    return array;
}
Also used : JsonArray(com.google.gson.JsonArray)

Example 57 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcResultTest method shouldGetAsListOfStringWhenParsingStringWithResultAsString.

@Test
public void shouldGetAsListOfStringWhenParsingStringWithResultAsString() throws Exception {
    String expected = "a";
    JsonPrimitive primitive = new JsonPrimitive(expected);
    JsonArray array = new JsonArray();
    array.add(primitive);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(array.toString(), jsonParser);
    List<String> actual = jsonRpcResult.getAsListOf(String.class);
    assertEquals(expected, actual.iterator().next());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Example 58 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcParamsTest method shouldToJsonForCreatedListDoubleParams.

@Test
public void shouldToJsonForCreatedListDoubleParams() throws Exception {
    double value = 0D;
    List<Double> list = singletonList(value);
    JsonArray expected = new JsonArray();
    expected.add(new JsonPrimitive(value));
    JsonRpcParams jsonRpcParams = new JsonRpcParams(list, jsonParser);
    JsonElement actual = jsonRpcParams.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) Test(org.testng.annotations.Test)

Example 59 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcParamsTest method shouldToStringCreatedListBooleanParams.

@Test
public void shouldToStringCreatedListBooleanParams() throws Exception {
    Boolean value = false;
    List<Boolean> list = singletonList(value);
    JsonArray jsonArray = new JsonArray();
    jsonArray.add(new JsonPrimitive(value));
    String expected = jsonArray.toString();
    JsonRpcParams jsonRpcParams = new JsonRpcParams(list, jsonParser);
    String actual = jsonRpcParams.toString();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 60 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcListTest method shouldToJsonArrayCreatedBooleanArray.

@Test
public void shouldToJsonArrayCreatedBooleanArray() throws Exception {
    JsonArray expected = new JsonArray();
    expected.add(new JsonPrimitive(false));
    JsonRpcList jsonRpcList = new JsonRpcList(singletonList(false), jsonParser);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Aggregations

JsonArray (com.google.gson.JsonArray)424 JsonObject (com.google.gson.JsonObject)290 JsonElement (com.google.gson.JsonElement)167 JsonPrimitive (com.google.gson.JsonPrimitive)118 Test (org.testng.annotations.Test)59 JsonParser (com.google.gson.JsonParser)57 ArrayList (java.util.ArrayList)50 HashMap (java.util.HashMap)34 Map (java.util.Map)34 Gson (com.google.gson.Gson)22 IOException (java.io.IOException)17 Test (org.junit.Test)16 Type (java.lang.reflect.Type)12 List (java.util.List)11 Matchers.anyString (org.mockito.Matchers.anyString)10 TextView (android.widget.TextView)9 Point (android.graphics.Point)8 JsonParseException (com.google.gson.JsonParseException)7 GsonUtilities.jboolean (com.ibm.streamsx.topology.internal.gson.GsonUtilities.jboolean)7 KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)6